@@ -6,111 +6,112 @@ import { ATOM_GROUP_NAME } from "../enums";
6
6
* Mixin containing the logic for dealing with atoms.
7
7
* Draws atoms as spheres and handles actions performed on them.
8
8
*/
9
- export const AtomsMixin = ( superclass ) => class extends superclass {
10
- constructor ( config ) {
11
- super ( config ) ;
9
+ export const AtomsMixin = ( superclass ) =>
10
+ class extends superclass {
11
+ constructor ( config ) {
12
+ super ( config ) ;
12
13
13
- // to draw atoms as spheres
14
- this . initSphereParameters ( ) ;
14
+ // to draw atoms as spheres
15
+ this . initSphereParameters ( ) ;
15
16
16
- this . drawAtomsAsSpheres = this . drawAtomsAsSpheres . bind ( this ) ;
17
- this . getAtomColorByElement = this . getAtomColorByElement . bind ( this ) ;
17
+ this . drawAtomsAsSpheres = this . drawAtomsAsSpheres . bind ( this ) ;
18
+ this . getAtomColorByElement = this . getAtomColorByElement . bind ( this ) ;
18
19
19
- this . setStructure ( this . _structure ) ;
20
- }
20
+ this . setStructure ( this . _structure ) ;
21
+ }
21
22
22
- get structure ( ) {
23
- return this . _structure ;
24
- }
23
+ get structure ( ) {
24
+ return this . _structure ;
25
+ }
25
26
26
- /**
27
+ /**
27
28
* Helper function to set the structural information.
28
29
* @param {Made.Material } s - Structural information as Made.Material.
29
30
*/
30
- setStructure ( s ) {
31
- this . _structure = s . clone ( ) ; // clone original structure to assert that any updates are propagated to parents
32
- this . _basis = s . Basis ;
33
- this . _basis . originalUnits = this . _basis . units ;
34
- this . _basis . toCartesian ( ) ;
35
- }
36
-
37
- get basis ( ) {
38
- return this . _basis ;
39
- }
40
-
41
- initSphereParameters ( ) {
42
- // radius, segment, ring
43
- const sphereGeometry = new THREE . SphereGeometry (
44
- 1 ,
45
- this . settings . sphereQuality ,
46
- this . settings . sphereQuality ,
47
- ) ;
48
- const sphereMaterial = new THREE . MeshLambertMaterial ( ) ;
49
- this . sphereMesh = new THREE . Mesh ( sphereGeometry , sphereMaterial ) ;
50
- }
51
-
52
- /**
31
+ setStructure ( s ) {
32
+ this . _structure = s . clone ( ) ; // clone original structure to assert that any updates are propagated to parents
33
+ this . _basis = s . Basis ;
34
+ this . _basis . originalUnits = this . _basis . units ;
35
+ this . _basis . toCartesian ( ) ;
36
+ }
37
+
38
+ get basis ( ) {
39
+ return this . _basis ;
40
+ }
41
+
42
+ initSphereParameters ( ) {
43
+ // radius, segment, ring
44
+ const sphereGeometry = new THREE . SphereGeometry (
45
+ 1 ,
46
+ this . settings . sphereQuality ,
47
+ this . settings . sphereQuality ,
48
+ ) ;
49
+ const sphereMaterial = new THREE . MeshLambertMaterial ( ) ;
50
+ this . sphereMesh = new THREE . Mesh ( sphereGeometry , sphereMaterial ) ;
51
+ }
52
+
53
+ /**
53
54
* Prepares a sphere mesh object
54
55
* @param {String } color
55
56
* @param {Number } radius
56
57
* @param {Array } coordinate
57
58
* @return {THREE.Object3D }
58
59
*/
59
- getSphereMeshObject ( {
60
- color = this . settings . defaultColor ,
61
- radius = this . settings . sphereRadius ,
62
- coordinate = [ ] ,
63
- } ) {
64
- // clone original mesh to optimize the speed
65
- const sphereMesh = this . sphereMesh . clone ( ) ;
66
- // set material color after cloning to optimize the speed and avoid re-creating material object
67
- sphereMesh . material = sphereMesh . material . clone ( ) ;
68
- sphereMesh . material . setValues ( { color } ) ;
69
-
70
- // eslint-disable-next-line no-multi-assign
71
- sphereMesh . scale . x = sphereMesh . scale . y = sphereMesh . scale . z = radius ;
72
- sphereMesh . position . set ( ...coordinate ) ;
73
-
74
- return sphereMesh ;
75
- }
76
-
77
- _getDefaultSettingsForElement (
78
- element = this . settings . defaultElement ,
79
- scale = this . settings . atomRadiiScale ,
80
- ) {
81
- return {
82
- color : this . getAtomColorByElement ( element ) ,
83
- radius : this . getAtomRadiusByElement ( element , scale ) ,
84
- } ;
85
- }
86
-
87
- createAtomsGroup ( basis , atomRadiiScale ) {
88
- const atomsGroup = new THREE . Group ( ) ;
89
- atomsGroup . name = ATOM_GROUP_NAME ;
90
- basis . coordinates . forEach ( ( atomicCoordinate , atomicIndex ) => {
91
- const element = basis . getElementByIndex ( atomicIndex ) ;
92
- const sphereMesh = this . getSphereMeshObject ( {
93
- ...this . _getDefaultSettingsForElement ( element , atomRadiiScale ) ,
94
- coordinate : atomicCoordinate . value ,
60
+ getSphereMeshObject ( {
61
+ color = this . settings . defaultColor ,
62
+ radius = this . settings . sphereRadius ,
63
+ coordinate = [ ] ,
64
+ } ) {
65
+ // clone original mesh to optimize the speed
66
+ const sphereMesh = this . sphereMesh . clone ( ) ;
67
+ // set material color after cloning to optimize the speed and avoid re-creating material object
68
+ sphereMesh . material = sphereMesh . material . clone ( ) ;
69
+ sphereMesh . material . setValues ( { color } ) ;
70
+
71
+ // eslint-disable-next-line no-multi-assign
72
+ sphereMesh . scale . x = sphereMesh . scale . y = sphereMesh . scale . z = radius ;
73
+ sphereMesh . position . set ( ...coordinate ) ;
74
+
75
+ return sphereMesh ;
76
+ }
77
+
78
+ _getDefaultSettingsForElement (
79
+ element = this . settings . defaultElement ,
80
+ scale = this . settings . atomRadiiScale ,
81
+ ) {
82
+ return {
83
+ color : this . getAtomColorByElement ( element ) ,
84
+ radius : this . getAtomRadiusByElement ( element , scale ) ,
85
+ } ;
86
+ }
87
+
88
+ createAtomsGroup ( basis , atomRadiiScale ) {
89
+ const atomsGroup = new THREE . Group ( ) ;
90
+ atomsGroup . name = ATOM_GROUP_NAME ;
91
+ basis . coordinates . forEach ( ( atomicCoordinate , atomicIndex ) => {
92
+ const element = basis . getElementByIndex ( atomicIndex ) ;
93
+ const sphereMesh = this . getSphereMeshObject ( {
94
+ ...this . _getDefaultSettingsForElement ( element , atomRadiiScale ) ,
95
+ coordinate : atomicCoordinate . value ,
96
+ } ) ;
97
+ sphereMesh . name = `${ element } -${ atomicIndex } ` ;
98
+ atomsGroup . add ( sphereMesh ) ;
95
99
} ) ;
96
- sphereMesh . name = `${ element } -${ atomicIndex } ` ;
97
- atomsGroup . add ( sphereMesh ) ;
98
- } ) ;
99
- return atomsGroup ;
100
- }
101
-
102
- drawAtomsAsSpheres ( atomRadiiScale ) {
103
- const basis = this . areNonPeriodicBoundariesPresent
104
- ? this . basisWithElementsInsideNonPeriodicBoundaries
105
- : this . basis ;
106
- this . repeatAtomsAtRepetitionCoordinates ( this . createAtomsGroup ( basis , atomRadiiScale ) ) ;
107
- }
108
-
109
- getAtomColorByElement ( element , pallette = this . settings . elementColors ) {
110
- return pallette [ element ] || this . settings . defaultColor ;
111
- }
112
-
113
- getAtomRadiusByElement ( element , scale = 1.0 , radiimap = this . settings . vdwRadii ) {
114
- return ( radiimap [ element ] || this . settings . sphereRadius ) * scale ;
115
- }
116
- } ;
100
+ return atomsGroup ;
101
+ }
102
+
103
+ drawAtomsAsSpheres ( atomRadiiScale ) {
104
+ const basis = this . areNonPeriodicBoundariesPresent
105
+ ? this . basisWithElementsInsideNonPeriodicBoundaries
106
+ : this . basis ;
107
+ this . repeatAtomsAtRepetitionCoordinates ( this . createAtomsGroup ( basis , atomRadiiScale ) ) ;
108
+ }
109
+
110
+ getAtomColorByElement ( element , pallette = this . settings . elementColors ) {
111
+ return pallette [ element ] || this . settings . defaultColor ;
112
+ }
113
+
114
+ getAtomRadiusByElement ( element , scale = 1.0 , radiimap = this . settings . vdwRadii ) {
115
+ return ( radiimap [ element ] || this . settings . sphereRadius ) * scale ;
116
+ }
117
+ } ;
0 commit comments