-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCluster.java
More file actions
216 lines (189 loc) · 4.87 KB
/
Cluster.java
File metadata and controls
216 lines (189 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
public class Cluster implements Particle{
//private Atom[] atoms;
private Particle[] parts;
private Vector[] neutralPositions;
private Quaternion rotation;
private Vector center;
private boolean picked;
private boolean hidden;
public Cluster(Particle[] stuff){
parts = stuff;
calculateCenter();
pick(true);
//hide(false);
neutralPositions = new Vector[parts.length];
for(int i=0; i<parts.length; i++){
neutralPositions[i] = parts[i].getCoordinates().minus(center);
}
rotation = new Quaternion(1.0,0.0,0.0,0.0);
}
public Cluster copy(){
Particle[] stuff = new Particle[this.countParticles()];
for(int i=0; i<stuff.length; i++){
stuff[i] = this.parts[i].copy();
}
Cluster newC = new Cluster(stuff);
newC.neutralPositions = new Vector[this.neutralPositions.length];
for(int i=0; i<this.neutralPositions.length; i++){
newC.neutralPositions[i] = this.neutralPositions[i].copy();
}
newC.rotation = this.rotation.copy();
newC.picked = this.picked;
newC.hidden = this.hidden;
return newC;
}
public boolean isSimilarTo(Particle another){
if(this.countParticles() != another.countParticles()){
return false;
}
for(int i=0; i<parts.length; i++){
if(!parts[i].isSimilarTo(another.getParticle(i))){
return false;
}
}
return true;
}
public Vector getCoordinates(){
return this.center;
}
public void scale(double factor){
for(int i=0; i<parts.length; i++){
if(parts[i].isAtomic()){
neutralPositions[i] = neutralPositions[i].times(factor);
} else {
((Cluster)parts[i]).scale(factor);
}
}
updateAtomPositions();
}
private void updateAtomPositions(){
for(int i=0; i<parts.length; i++){
if(parts[i].isAtomic()){
Vector newc = neutralPositions[i].rotate(rotation).plus(center);
parts[i].setCoordinates(newc);
} else {
Vector newc = neutralPositions[i].rotate(rotation).plus(center);
parts[i].setCoordinates(newc);
((Cluster)parts[i]).updateAtomPositions();
}
}
}
public void setCoordinates(Vector newc){
this.center = newc;
updateAtomPositions();
}
public void shiftCoordinates(Vector dc){
this.center = this.center.plus(dc);
updateAtomPositions();
}
public void rotate(Quaternion rot){
this.rotation = rot.times(this.rotation);
for(int i=0; i<parts.length; i++){
parts[i].rotate(rot);
}
updateAtomPositions();
}
private void calculateCenter(){
double[] cc = new double[3];
for(int i=0; i<3; i++){
cc[i] = 0.0;
}
Atom[] atoms = getAtoms();
for(int j=0; j<atoms.length; j++){
for(int i=0; i<3; i++){
cc[i] += atoms[j].getCoordinates().element(i);
}
}
for(int i=0; i<3; i++){
cc[i] /= atoms.length;
}
center = new Vector(cc);
}
public double getMass(){
double m = 0.0;
Atom[] atoms = getAtoms();
for(int i=0; i<atoms.length; i++){
m += atoms[i].getMass();
}
return m;
}
public Atom[] getAtoms(){
int nat = countAtoms();
Atom[] atoms = new Atom[nat];
int j=0;
for(int i=0; i<parts.length; i++){
if(parts[i].isAtomic()){
atoms[j] = (Atom)parts[i];
j++;
} else {
Atom[] list = parts[i].getAtoms();
for(int k=0; k<list.length; k++){
atoms[j] = list[k];
j++;
}
}
}
return atoms;
}
public Particle[] getParticles(){
return this.parts;
}
public Particle getParticle(int index){
return this.parts[index];
}
public int countAtoms(){
int nat = 0;
for(int i=0; i<parts.length; i++){
nat += parts[i].countAtoms();
}
return nat;
}
public int countParticles(){
return parts.length;
}
public Quaternion getOrientation(){
return this.rotation;
}
public void pick(boolean yesno){
this.picked = yesno;
for(int i=0; i<parts.length; i++){
parts[i].pick(yesno);
}
}
public void hide(boolean yesno){
this.hidden = yesno;
for(int i=0; i<parts.length; i++){
parts[i].hide(yesno);
}
}
public boolean isPicked(){
return this.picked;
}
public boolean isHidden(){
return this.hidden;
}
public boolean isAtomic(){
return false;
}
public String toString(){
String info = "cluster ";
info += "of "+FileHandler.formattedInt(countAtoms(),4)+" ";
info += " ("+FileHandler.formattedDouble(center.element(0),12,6)+
", "+FileHandler.formattedDouble(center.element(1),12,6)+
", "+FileHandler.formattedDouble(center.element(2),12,6)+")";
return info;
}
public void invertByPlane(Vector normal, Vector point){
Vector axis = this.rotation.rotationAxis();
double angle = this.rotation.rotationAngle();
// Internal reflection
Vector internalNormal = normal.rotate(new Quaternion(axis,-angle));
for(int i=0; i<parts.length; i++){
neutralPositions[i] = neutralPositions[i].inversionByPlane(internalNormal,new Vector(0,0,0));
if(!parts[i].isAtomic()){
((Cluster)parts[i]).invertByPlane(normal,point);
}
}
updateAtomPositions();
}
}