-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCluster.cpp
More file actions
1094 lines (932 loc) · 31.5 KB
/
CCluster.cpp
File metadata and controls
1094 lines (932 loc) · 31.5 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "CCluster.h"
using namespace std;
ostream& operator<<(ostream& os, const CCluster& c)
// Inputs: ostream(os) - Output stream (open)
// CCluster(c) - Cluster
// Outputs: ostream(os) - To file
{
os << " " << c.n_atoms << endl;
os << setiosflags (ios::left|ios::fixed) << setprecision(8) << " " << c.energy << endl;
for(int i = 0; i < c.n_atoms; i++)
{
os << setiosflags ( ios::right|ios::fixed ) << setprecision(12) << c.atom_vec[i].atom_type << " "
<< setw(16) << c.atom_vec[i].x * c.bond_scale_factor << " "
<< setw(16) << c.atom_vec[i].y * c.bond_scale_factor << " "
<< setw(16) << c.atom_vec[i].z * c.bond_scale_factor;
os << endl;
}
return os;
}
bool CCluster::operator ==(CCluster a)
// Checks if cluster has rotated or scaled for tolerance
// Inputs: CCluster(a) - Cluster
// Outputs: bool - Tolerance checking
{
if(this->n_atoms != a.n_atoms) //Check to make sure cluster are of equal size first
{
return false;
}
this->origin(); // Move to Origin
a.origin(); // Move to Origin
for(int i = 0; i < this->n_atoms; i++) // Check for displacement will return false if rotation of one cluster has occured
{
double bond;
bond = bond_length(this->atom_vec[i].x,a.atom_vec[i].x,this->atom_vec[i].y,a.atom_vec[i].y,this->atom_vec[i].z,a.atom_vec[i].z);
if (bond > 0.5) return false; // 0.5 is an arbitrary tolerance value. We are working in Angstrom
}
return true;
}
CCluster::CCluster()
// Initialise
{
n_atoms = 0; // We can use this to tell if the object is empty
}
//CCluster::~CCluster()
//{
// //delete &atom_vec;
//}
CCluster::CCluster(string structure_filename)
// Read Structure from file
// Input: string(structure_filename) -
{
string line;
ifstream structure_file;
atom temp;
structure_file.open(structure_filename.c_str(), ios::in);
if(!structure_file.is_open())
{
cout << "Structure file (" << structure_filename << ") does not exist" << endl;
exit(1);
}
else
{
getline(structure_file, line); // Get number of atoms
StringToNumber(line, n_atoms);
getline(structure_file, line); // Get energy
if (line.size() != 0) StringToNumber(line, energy);
while(!structure_file.eof())
{
vector<string> tokens;
getline(structure_file, line);
Tokenize(line, tokens, " \t");
if (line.size() != 0)
{
temp.atom_type = tokens[0];
StringToNumber(tokens[1], temp.x);
StringToNumber(tokens[2], temp.y);
StringToNumber(tokens[3], temp.z);
atom_vec.push_back(temp);
}
}
atom_type();
bond_scale_factor = 1.0;
structure_file.close();
}
//printatoms(); //Debugging
}
void CCluster::atom_type()
// Work out atom types
{
string test;
n_atomsb = n_atomsa = 0; // Set number of atoms of each type
element_a = test = atom_vec[0].atom_type; // Set initial atom type
for(int i = 0; i < n_atoms; i++) // Work out atom types. Designed for bimetallic system, but will just do all atoms of first type and then all other atom types
if(test == atom_vec[i].atom_type) n_atomsa++;
else element_b = atom_vec[i].atom_type;
n_atomsb = n_atoms - n_atomsa;
}
bool CCluster::same_atom(atom* aptr_1, atom* aptr_2)
// Check if two atoms are the same
// Input: atom(aptr_1) - Pointer to atom 1
// atom(aptr_2) - Pointer to atom 2
// Output: boolean
{
if(aptr_1->atom_type != aptr_2->atom_type)
return false;
if(aptr_1->identity != aptr_2->identity)
return false;
if(aptr_1->x != aptr_2->x)
return false;
if(aptr_1->y != aptr_2->y)
return false;
if(aptr_1->z != aptr_2->z)
return false;
return true;
}
double CCluster::bond_length(const double &aX, const double &bX, const double &aY, const double &bY, const double &aZ, const double &bZ)
// Calculate distance between two atoms
// Inputs: double(aX) - atom A, X coordinate
// double(bX) - atom B, X coordinate
// double(aY) - atom A, Y coordinate
// double(bY) - atom B, Y coordinate
// double(aZ) - atom A, Z coordinate
// double(bZ) - atom B, Z coordinate
// Outputs: double - atom displacements
{
double bond, x_displacement, y_displacement, z_displacement;
x_displacement = pow(aX-bX,2); // Square differences
y_displacement = pow(aY-bY,2);
z_displacement = pow(aZ-bZ,2);
bond = sqrt(x_displacement+y_displacement+z_displacement); // And square root total. Simple geometric algebra.
return bond;
}
vector<string> CCluster::avg_bond_length(const string &a, const string &b, const float cutoff)
// Gives average bond length data
// Inputs: string(a) - atom A type
// string(b) - atom B type
// float(cutoff) - maximum distance we will pay attention to
// Outputs: vector<string> - List of strings with results to be displayed
{
double bond , max_bond, min_bond, total;
min_bond = cutoff;
bond = max_bond = total = 0.0;
int count = 0;
for(int first_atom = 0; first_atom < n_atoms; first_atom++)
for(int second_atom = first_atom+1; second_atom < n_atoms; second_atom++)
if( (atom_vec[first_atom].atom_type.compare(a)+atom_vec[second_atom].atom_type.compare(b) == 0) ||
(atom_vec[second_atom].atom_type.compare(b)+atom_vec[first_atom].atom_type.compare(a) == 0))
{
bond = bond_length(atom_vec[first_atom].x,atom_vec[second_atom].x,atom_vec[first_atom].y,atom_vec[second_atom].y,atom_vec[first_atom].z,atom_vec[second_atom].z);
if (bond < cutoff)
{
total += bond;
if (bond < min_bond) min_bond = bond;
if (bond > max_bond) max_bond = bond;
count++;
}
}
// std::cout << "Atom A: " << a << std::endl;
// std::cout << "Atom B: " << b << std::endl;
// std::cout << "Bond Length Cutoff: " << cutoff << std::endl;
// std::cout << "Number of A-B bonds: " << count << std::endl;
// std::cout << "Average Bond Length: " << total/count << std::endl;
// std::cout << "Minimum Bond Length: " << min_bond << std::endl;
// std::cout << "Maximum Bond Length: " << max_bond << std::endl;
string temp;
vector<string> out;
bond = total/count;
temp = "Atom A: "; temp += a; out.push_back(temp);
temp = "Atom B: "; temp += b; out.push_back(temp);
NumberToString(cutoff,temp); temp = "Bond Length Cutoff: " + temp; out.push_back(temp);
NumberToString(count,temp); temp = "Number of A-B Bonds: " + temp; out.push_back(temp);
NumberToString(bond,temp); temp = "Average Bond Length: " + temp; out.push_back(temp);
NumberToString(min_bond,temp); temp = "Minimum Bond Length: " + temp; out.push_back(temp);
NumberToString(max_bond,temp); temp = "Maximum Bond Length: " + temp; out.push_back(temp);
return out;
}
void CCluster::rotate_x_axis(const double &radians)
// Rotate cluster coordinates around x axis
// Input double(radians) - Degrees to rotate
{
double temp_y, temp_z;
for(int i = 0; i < n_atoms; i++)
{
temp_y = atom_vec[i].y * cos(radians) + atom_vec[i].z * sin(radians);
temp_z = atom_vec[i].z * cos(radians) - atom_vec[i].y * sin(radians);
atom_vec[i].y = temp_y;
atom_vec[i].z = temp_z;
}
}
void CCluster::rotate_y_axis(const double &radians)
// Rotate cluster coordinates around y axis
// Input double(radians) - Degrees to rotate
{
double temp_x, temp_z;
for(int i = 0; i < n_atoms; i++)
{
temp_x = atom_vec[i].x * cos(radians) - atom_vec[i].z * sin(radians);
temp_z = atom_vec[i].x * sin(radians) + atom_vec[i].z * cos(radians);
atom_vec[i].x = temp_x;
atom_vec[i].z = temp_z;
}
}
void CCluster::rotate_z_axis(const double &radians)
// Rotate cluster coordinates around z axis
// Input double(radians) - Degrees to rotate
{
double temp_y, temp_x;
for(int i = 0; i < n_atoms; i++)
{
temp_x = atom_vec[i].x * cos(radians) + atom_vec[i].y * sin(radians);
temp_y = atom_vec[i].y * cos(radians) - atom_vec[i].x * sin(radians);
atom_vec[i].y = temp_y;
atom_vec[i].x = temp_x;
}
}
void CCluster::shift_origin(atom *ptr)
// Shift origin to selected atom
// Input atom(ptr) - Pointer to atom to be used as origin
{
origin();
translate(ptr->x,ptr->y,ptr->z);
}
void CCluster::translate(float x, float y, float z)
// Translate atoms to new point
// Input float(x) - X displacement
// float(y) - Y displacement
// float(z) - Z displacement
{
for(int i = 0; i < n_atoms; i++)
{
atom_vec[i].x += x;
atom_vec[i].y += y;
atom_vec[i].z += z;
}
}
void CCluster::shift_origin(atom &temp)
// Shift origin to selected atom
// Input atom(temp) - Atom to be referenced
{
origin();
translate(temp.x,temp.y,temp.z); // Get translate to do the work here
}
void CCluster::slice(const double &x, const double &y, const double &z)
// Slice molecule through give vector
// Input double(x) - x coordinate
// double(y) - y coordinate
// double(z) - z coordinate
{
origin();
std::vector<atom> SlicedModel;
for(int i = 0; i < n_atoms; i++)
if((atom_vec[i].x < x) && (atom_vec[i].y) < y && (atom_vec[i].z < z)){}
else SlicedModel.push_back(atom_vec[i]);
atom_vec = SlicedModel;
n_atoms = SlicedModel.size();
atom_type();
}
void CCluster::origin()
// Centralise cluster
{
double avg_x, avg_y, avg_z;
avg_x = avg_y = avg_z = 0;
for( int i = 0; i < n_atoms; i++)
{
avg_x += atom_vec[i].x;
avg_y += atom_vec[i].y;
avg_z += atom_vec[i].z;
}
avg_x /= n_atoms;
avg_y /= n_atoms;
avg_z /= n_atoms;
for( int i = 0; i < n_atoms; i++)
{
atom_vec[i].x -= avg_x;
atom_vec[i].y -= avg_y;
atom_vec[i].z -= avg_z;
}
}
double CCluster::CalcMeanRadius()
// Work out mean radius for whole cluster of certain type
// Output: double - average distance from origin to atoms
{
double meanRadius;
double radius_sum = 0.0;
//Well before we do anything we best make sure the cluster COM is numerically found
origin();
for(int i = 0; i < n_atoms; i++)
radius_sum += bond_length(atom_vec[i].x,0,atom_vec[i].y,0,atom_vec[i].z,0);
meanRadius = (radius_sum/n_atoms);
return meanRadius;
}
double CCluster::CalcMeanRadius(const string &a)
// Work out mean radius for atoms of certain type
// Input: string(a) - atom type
// Output: double - average distance from origin to atoms
{
double meanRadius;
double radius_sum = 0.0;
int Na = 0;
//Well before we do anything we best make sure the cluster COM is numerically found
origin();
for(int i = 0; i < n_atoms; i++)
{
if( a == atom_vec[i].atom_type )
{
radius_sum += bond_length(atom_vec[i].x,0,atom_vec[i].y,0,atom_vec[i].z,0);
Na++;
}
}
meanRadius = (radius_sum/Na);
return meanRadius;
}
void CCluster::scale(float x, float y, float z)
// Scale atom coordinates
// Input: float(x) - x scalar
// float(y) - y scalar
// float(z) - z scalar
{
for(int currentAtom = 0; currentAtom < n_atoms; currentAtom++)
{
atom_vec[currentAtom].x *= x;
atom_vec[currentAtom].y *= y;
atom_vec[currentAtom].z *= z;
}
}
void CCluster::radial_Scale(float percentage)
// Scale atom coordinates by percentage
// Input: float(percentage) - says on the tin
{
double nu = 100 + percentage;
vec3d origin,new_point,atom;
origin.x = 0;
origin.y = 0;
origin.z = 0;
for(int i = 0; i < n_atoms; i++)
{
atom.x = atom_vec[i].x;
atom.y = atom_vec[i].y;
atom.z = atom_vec[i].z;
point_on_3D_line(origin,atom, new_point,nu);
atom_vec[i].x = new_point.x;
atom_vec[i].y = new_point.y;
atom_vec[i].z = new_point.z;
}
}
void CCluster::calc_surface_energy()
{
double x,y,z,length,length1;
for(int i = 0; i < n_atoms-2; i++)
{
for(int j = i+1; j < n_atoms-1; j++)
{
x = atom_vec[j].x - atom_vec[i].x;
y = atom_vec[j].y - atom_vec[i].y;
z = atom_vec[j].z - atom_vec[i].z;
length = sqrt( x*x + y*y + z*z);
if(length > 0 && length < 3.8) //REALLY NEED TO SET THIS TO A VARIABLE and not just 3.8
{
for(int k = j+1; k < n_atoms; k++)
{
x = atom_vec[k].x - atom_vec[i].x;
y = atom_vec[k].y - atom_vec[i].y;
z = atom_vec[k].z - atom_vec[i].z;
length = sqrt( x*x + y*y + z*z);
x = atom_vec[j].x - atom_vec[k].x;
y = atom_vec[j].y - atom_vec[k].y;
z = atom_vec[j].z - atom_vec[k].z;
length1 = sqrt( x*x + y*y + z*z);
//cout << "n_atoms = " << n_atoms << " i = " << i << " J = " << j << " K = " << k << endl;
//cout << "Size of plane vector = " << atom_plane.size() << endl;
if(length > 0 && length < 3.8 && length1 > 0 && length1 < 3.8)
{
//Then We have a candiate plane?
plane temp_plane;
temp_plane.patom_1 = &atom_vec[i];
temp_plane.patom_2 = &atom_vec[j];
temp_plane.patom_3 = &atom_vec[k];
temp_plane.surface = false;
atom_plane.push_back(temp_plane);
}
}
}
}
}
//===========================
//All of the Above finds all nearest neighbour planes and adds them to a vector of planes
//Now simple go through each plane and deduce if it is a surface or interior plane.
//
// CURRENT PROBLEMS WITH CODE BELOW THE ATOMVEC and PLANE data types dont comunicate
//===========================
double a,b, angleA, angleB, angleC, temp;
angleA = angleB = angleC = 0.0;
double x1, y1;
atom cofm;
for(unsigned int i = 0; i < atom_plane.size(); i++)
{
shift_origin(atom_plane[i].patom_1); //Shift the origin to atom on of plane
//Now work out the angle between the origin and atom2 and bring it in to the x axis using tangent
a = atom_plane[i].patom_2->y * atom_plane[i].patom_2->y;
b = atom_plane[i].patom_2->x * atom_plane[i].patom_2->x;
a = sqrt(a);
b = sqrt(b);
temp = a/b;
if( atom_plane[i].patom_2->x > 0.0 && atom_plane[i].patom_2->y > 0.0 )
{
//cout << "No Change (+x,+y)" << endl;
angleA = atan(temp);
}
if( atom_plane[i].patom_2->x > 0.0 && atom_plane[i].patom_2->y < 0.0 )
{
//cout << "-1 * angle(+x,-y)" << endl;
angleA = atan(temp);
angleA = -1 * angleA;
}
if( atom_plane[i].patom_2->x < 0.0 && atom_plane[i].patom_2->y < 0.0 )
{
//cout << "No Change (-x,-y)" << endl;
angleA = atan(temp);
}
if( atom_plane[i].patom_2->x < 0.0 && atom_plane[i].patom_2->y > 0.0 )
{
//cout << "-1 * angle (-x,+y)" << endl;
angleA = atan(temp);
angleA = -1 * angleA;
}
if( atom_plane[i].patom_2->y == 0.0 )
{
//cout << "Atom is 0 y z rotation" << endl;
angleA = 0;
}
//cout << "----------------" << endl;
//cout << "Before" << endl;
//cout << atom_plane[i].patom_2->z << "\t" << atom_plane[i].patom_2->y << endl;
rotate_z_axis(angleA); //Rotate system around
//cout << "After" << endl;
//cout << atom_plane[i].patom_2->z << "\t" << atom_plane[i].patom_2->y << endl;
//cout << "----------------" << endl;
//cout << endl;
//Now remove the z- componet of atom 2 in plane i
a = atom_plane[i].patom_2->z * atom_plane[i].patom_2->z;
b = atom_plane[i].patom_2->x * atom_plane[i].patom_2->x;
a = sqrt(a);
b = sqrt(b);
temp = a/b;
if( atom_plane[i].patom_2->x > 0 && atom_plane[i].patom_2->z > 0 )
{
//cout << "360 - angleB (x+,z+)" << endl;
angleB = atan(temp);
angleB = -1*angleB;
}
if( atom_plane[i].patom_2->x > 0 && atom_plane[i].patom_2->z < 0 )
{
//cout << "No change (+x, -z)" << endl;
angleB = atan(temp);
//angleB = 360*DEGTORAD - 180*DEGTORAD + angleB;
}
if( atom_plane[i].patom_2->x < 0 && atom_plane[i].patom_2->z < 0 )
{
//cout << "360 - angleB (-x, -z)" << endl;
angleB = atan(temp);
angleB = -1*angleB;
}
if( atom_plane[i].patom_2->x < 0 && atom_plane[i].patom_2->z > 0 )
{
//cout << "No Change (-x, +z)" << endl;
angleB = atan(temp);
//angleB = 360*DEGTORAD - (180*DEGTORAD + angleB);
}
if( atom_plane[i].patom_2->z == 0 )
{
//cout << "ZERO atom2 y rotation" << endl;
angleB = 0;
}
//cout << "Before" << endl;
//cout << atom_plane[i].patom_2->y << "\t and z " << atom_plane[i].patom_2->z << endl;
rotate_y_axis(angleB); // Rotate system
//cout << "after" << endl;
//cout << atom_plane[i].patom_2->y << "\t and z " << atom_plane[i].patom_2->z << endl;
//cout << endl;
/*
cout << "Atom 3 " << atom_plane[i].patom_3->x << "\t" << atom_plane[i].patom_3->y << "\t" << atom_plane[i].patom_3->z << endl;
cout << "Atom 3 id" << atom_plane[i].patom_3->identity << endl;
cout << "Atom 3 by vec " << atom_vec[5].x << "\t" << atom_vec[5].y << "\t" << atom_vec[5].z << "\t" << atom_vec[5].identity << endl;
cout << "-------------" << endl;
*/
//Finally bring the 3 atom of plane i z componet to zero so now 3 atoms lie in the xy plane
a = atom_plane[i].patom_3->z * atom_plane[i].patom_3->z;
b = atom_plane[i].patom_3->y * atom_plane[i].patom_3->y;
a = sqrt(a);
b = sqrt(b);
temp = a/b;
if( atom_plane[i].patom_3->y > 0 && atom_plane[i].patom_3->z > 0 )
{
//cout << "no change (+y,+z)" << endl;
angleC = atan(temp);
//angleC = 360*DEGTORAD - (180*DEGTORAD + angleC);
}
if( atom_plane[i].patom_3->y > 0 && atom_plane[i].patom_3->z < 0 )
{
//cout << " -1*angleC (+y,-z)" << endl;
angleC = atan(temp);
angleC = -1*angleC;
}
if( atom_plane[i].patom_3->y < 0 && atom_plane[i].patom_3->z < 0 )
{
//cout << "no change (-y,-z)" << endl;
angleC = atan(temp);
//angleC = 360*DEGTORAD + angleC;
}
if( atom_plane[i].patom_3->y < 0 && atom_plane[i].patom_3->z > 0 )
{
//cout << "-1 * angleC (-y,+z)" << endl;
angleC = atan(temp);
angleC = -1* angleC;
}
if( atom_plane[i].patom_3->z == 0 )
{
//cout << "ZERO atom_3 x rotation" << endl;
angleC = 0;
}
//cout << "Before" << endl;
//cout << "y = " << atom_plane[i].patom_3->y << " z = " << atom_plane[i].patom_3->z << endl;
rotate_x_axis(angleC); //Preform the rotation
//DO YOU REMEBER WHY YOU DID ALL THE ABOVE BEN, I THINK NOT
//cout << "After" << endl;
//cout << "y = " << atom_plane[i].patom_3->y << " z = " << atom_plane[i].patom_3->z << endl;
//cout << endl;
//Ok plane is now orientated by to x,y plane any atoms lying above and below z axis make this plane interior
/*
cout << "Atom 1 " << atom_plane[i].patom_1->x << "\t" << atom_plane[i].patom_1->y << "\t" << atom_plane[i].patom_1->z << endl;
cout << "Atom 2 " << atom_plane[i].patom_2->x << "\t" << atom_plane[i].patom_2->y << "\t" << atom_plane[i].patom_2->z << endl;
cout << "Atom 3 " << atom_plane[i].patom_3->x << "\t" << atom_plane[i].patom_3->y << "\t" << atom_plane[i].patom_3->z << endl;
cout << "Atom 3 id" << atom_plane[i].patom_3->identity << endl;
cout << "Atom 3 by vec " << atom_vec[5].x << "\t" << atom_vec[5].y << "\t" << atom_vec[5].z << "\t" << atom_vec[5].identity << endl;
*/
//This make a new point which lies on the center of mass of the plane described by 3 atoms
x1 = atom_plane[i].patom_1->x + atom_plane[i].patom_2->x + atom_plane[i].patom_3->x;
y1 = atom_plane[i].patom_1->y + atom_plane[i].patom_2->y + atom_plane[i].patom_3->y;
cofm.x = x1/3.0;
cofm.y = y1/3.0;
cofm.z = 0.0;
shift_origin(cofm);
float near_zero = 1e-12; //anything less than this is smaller than the orignal coordination file input.
bool bIsNegative = false;
bool bIsPositive = false;
for(int j = 0; j < n_atoms; j++)
{
float distancexy; //Dilerberate lose of precision its a cutoff point if it 3.8 dont need all them zeros
float distancexyz, radius_cofm;
radius_cofm = 1.615;//THIS IS NOT IDEAL REALLY SHOULD BE CALCULATED FROM Atom Componenets SEE LAB BOOK
distancexy = atom_vec[j].x * atom_vec[j].x + atom_vec[j].y * atom_vec[j].y;
distancexy = sqrt(distancexy);
distancexyz = atom_vec[j].x * atom_vec[j].x + atom_vec[j].y * atom_vec[j].y + atom_vec[j].z * atom_vec[j].z;
if( distancexy < radius_cofm )//then it lies inside of plane radius cutoff
{
if( atom_vec[j].z < -near_zero || atom_vec[j].z > near_zero ) //Then there is an atom lying on onside of the plane
{
if( atom_vec[j].z < -near_zero ) //is it the negative side?
{
//cout << "Plane " << i << " has negative side" << endl;
bIsNegative = true;
}
if( atom_vec[j].z > near_zero ) // is it postive side ?
{
//cout << "Plane " << i << " has postive side" << endl;
bIsPositive = true;
}
if( bIsPositive && bIsNegative ) //Interior plane
{
atom_plane[i].surface = false;
break;
}
else
{
atom_plane[i].surface = true;
}
}
}
}
}
int surfaces = 0;
double surfacearea = 0;
for(unsigned int i = 0; i < atom_plane.size(); i++)
{
if(atom_plane[i].surface == true) //If the plane was found to be a surface plane
{
surface_planes.push_back(atom_plane[i]);
double a1, b1, c1, C;
a1=b1=c1=C=0.0;
//Area a*bsin(C)/2 area of a general triangle
a1 = (atom_plane[i].patom_1->x - atom_plane[i].patom_2->x)*(atom_plane[i].patom_1->x - atom_plane[i].patom_2->x) +
(atom_plane[i].patom_1->y - atom_plane[i].patom_2->y)*(atom_plane[i].patom_1->y - atom_plane[i].patom_2->y) +
(atom_plane[i].patom_1->z - atom_plane[i].patom_2->z)*(atom_plane[i].patom_1->z - atom_plane[i].patom_2->z);
a1 = sqrt(a1);
b1 = (atom_plane[i].patom_1->x - atom_plane[i].patom_3->x)*(atom_plane[i].patom_1->x - atom_plane[i].patom_3->x) +
(atom_plane[i].patom_1->y - atom_plane[i].patom_3->y)*(atom_plane[i].patom_1->y - atom_plane[i].patom_3->y) +
(atom_plane[i].patom_1->z - atom_plane[i].patom_3->z)*(atom_plane[i].patom_1->z - atom_plane[i].patom_3->z);
b1 = sqrt(b1);
c1 = (atom_plane[i].patom_3->x - atom_plane[i].patom_2->x)*(atom_plane[i].patom_3->x - atom_plane[i].patom_2->x) +
(atom_plane[i].patom_3->y - atom_plane[i].patom_2->y)*(atom_plane[i].patom_3->y - atom_plane[i].patom_2->y) +
(atom_plane[i].patom_3->z - atom_plane[i].patom_2->z)*(atom_plane[i].patom_3->z - atom_plane[i].patom_2->z);
c1 = sqrt(c1);
C = acos((a1*a1 + b1*b1 - c1*c1)/(2*a1*b1)); //law of cosines finds angle C which
//cout << "a1 = " << a1 << endl;
//cout << "b1 = " << b1 << endl;
//cout << "c1 = " << c1 << endl;
//cout << "C = " << C << endl;
surfacearea += a1 * b1 * sin(C)/ 2.0; //Area of that triangle;
surfaces++;
}
}
//cout << "Number of surface planes = " << surfaces << " out of " << atom_plane.size() << " planes " << structure << endl;
//cout << "Surface area = " << surfacearea << " Angstroms Squared " << endl;
surface_area = surfacearea;
}
void CCluster::print_surface_planes()
{
cout << "Plane" << "\t" << "atom 1" << "\t" << "atom 2" << "\t" << "atom 3" << endl;
for(unsigned int i = 0; i < surface_planes.size(); i++)
{
cout << i << "\t" << surface_planes[i].patom_1->identity << "\t" << surface_planes[i].patom_2->identity << "\t"
<< surface_planes[i].patom_3->identity
<< endl;
}
}
void CCluster::place_two_atoms_in_line_z_axis(int atom1, int atom2)
{
atom temp_atom = atom_vec[atom1];
shift_origin(temp_atom); //move origin to atom1
double a,b,angleA, angleB, temp;
a = atom_vec[atom2].y * atom_vec[atom2].y;
b = atom_vec[atom2].x * atom_vec[atom2].x;
a = sqrt(a);
b = sqrt(b);
temp = a/b;
if(atom_vec[atom2].x > 0.0 && atom_vec[atom2].y > 0.0) //We are in +x +y space
{
angleA = atan(temp);
}
if(atom_vec[atom2].x > 0.0 && atom_vec[atom2].y < 0.0) //We are in +x -y space
{
angleA = atan(temp);
angleA = -1.0 * angleA;
}
if(atom_vec[atom2].x < 0.0 && atom_vec[atom2].y < 0.0) //We are in -x -y space
{
angleA = atan(temp);
}
if(atom_vec[atom2].x < 0.0 && atom_vec[atom2].y > 0.0) //We are in -x +y space
{
angleA = atan(temp);
angleA = -1.0 * angleA;
}
if(atom_vec[atom2].y == 0.0)
{
angleA = 0;
}
rotate_z_axis(angleA);
a = atom_vec[atom2].z * atom_vec[atom2].z;
b = atom_vec[atom2].x * atom_vec[atom2].x;
a = sqrt(a);
b = sqrt(b);
temp = a/b;
if(atom_vec[atom2].x > 0.0 && atom_vec[atom2].z > 0.0) //We are in +x +y space
{
angleB = atan(temp);
}
if(atom_vec[atom2].x > 0.0 && atom_vec[atom2].z < 0.0) //We are in +x -y space
{
angleB = atan(temp);
angleB = -1.0 * angleB;
}
if(atom_vec[atom2].x < 0.0 && atom_vec[atom2].z < 0.0) //We are in -x -y space
{
angleB = atan(temp);
}
if(atom_vec[atom2].x < 0.0 && atom_vec[atom2].z > 0.0) //We are in -x +y space
{
angleB = atan(temp);
angleB = -1.0 * angleB;
}
if(atom_vec[atom2].z == 0.0)
{
angleB = 0;
}
rotate_y_axis(angleB); // Rotate system
origin();
rotate_y_axis(90*DEG2RAD);
}
void CCluster::place_furthest_atomic_distance_along_z_axis()
{
int atom1, atom2;
atom1 = atom2 = 0;
double distance, temp_distance;
distance = 0.0;
for( int i = 0; i < n_atoms; i++)
for( int j = i+1; j < n_atoms; j++)
{
temp_distance = bond_length(atom_vec[i].x,atom_vec[j].x,atom_vec[i].y,atom_vec[j].y,atom_vec[i].z,atom_vec[j].z);
if(temp_distance > distance)
{
distance = temp_distance;
atom1 = i;
atom2 = j;
}
}
//cout << atom1 << "\t" << atom2 << "\t" << distance << endl;
place_two_atoms_in_line_z_axis(atom1,atom2);
}
void CCluster::rotate_to_plane(int num)
{
plane p;
double a ,b , angleA, angleB, angleC, temp;
angleA = angleB = angleC = 0.0;
double x1, y1;
atom cofm;
p = surface_planes[num];
//Rotate to a surface plane
shift_origin(p.patom_1); //Shift the origin to atom on of plane i
//Now work out the angle between the origin and atom2 and bring it in to the x axis using tangent
a = p.patom_2->y * p.patom_2->y;
b = p.patom_2->x * p.patom_2->x;
a = sqrt(a);
b = sqrt(b);
temp = a/b;
if( p.patom_2->x > 0.0 && p.patom_2->y > 0.0 )
{
//cout << "No Change (+x,+y)" << endl;
angleA = atan(temp);
}
if( p.patom_2->x > 0.0 && p.patom_2->y < 0.0 )
{
//cout << "-1 * angle(+x,-y)" << endl;
angleA = atan(temp);
angleA = -1 * angleA;
}
if( p.patom_2->x < 0.0 && p.patom_2->y < 0.0 )
{
//cout << "No Change (-x,-y)" << endl;
angleA = atan(temp);
}
if( p.patom_2->x < 0.0 && p.patom_2->y > 0.0 )
{
//cout << "-1 * angle (-x,+y)" << endl;
angleA = atan(temp);
angleA = -1 * angleA;
}
if( p.patom_2->y == 0.0 )
{
//cout << "Atom is 0 y z rotation" << endl;
angleA = 0;
}
//cout << "----------------" << endl;
//cout << "Before" << endl;
//cout << p.patom_2->z << "\t" << p.patom_2->y << endl;
rotate_z_axis(angleA); //Rotate system around
//cout << "After" << endl;
//cout << p.patom_2->z << "\t" << p.patom_2->y << endl;
//cout << "----------------" << endl;
//cout << endl;
//Now remove the z- componet of atom 2 in plane i
a = p.patom_2->z * p.patom_2->z;
b = p.patom_2->x * p.patom_2->x;
a = sqrt(a);
b = sqrt(b);
temp = a/b;
if( p.patom_2->x > 0 && p.patom_2->z > 0 )
{
//cout << "360 - angleB (x+,z+)" << endl;
angleB = atan(temp);
angleB = -1*angleB;
}
if( p.patom_2->x > 0 && p.patom_2->z < 0 )
{
//cout << "No change (+x, -z)" << endl;
angleB = atan(temp);
//angleB = 360*DEGTORAD - 180*DEGTORAD + angleB;
}
if( p.patom_2->x < 0 && p.patom_2->z < 0 )
{
//cout << "360 - angleB (-x, -z)" << endl;
angleB = atan(temp);
angleB = -1*angleB;
}
if( p.patom_2->x < 0 && p.patom_2->z > 0 )
{
//cout << "No Change (-x, +z)" << endl;
angleB = atan(temp);
//angleB = 360*DEGTORAD - (180*DEGTORAD + angleB);
}
if( p.patom_2->z == 0 )
{
//cout << "ZERO atom2 y rotation" << endl;
angleB = 0;
}
//cout << "Before" << endl;
//cout << p.patom_2->y << "\t and z " << p.patom_2->z << endl;
rotate_y_axis(angleB); // Rotate system
//cout << "after" << endl;
//cout << p.patom_2->y << "\t and z " << p.patom_2->z << endl;
//cout << endl;
/*
cout << "Atom 3 " << p.patom_3->x << "\t" << p.patom_3->y << "\t" << p.patom_3->z << endl;
cout << "Atom 3 id" << p.patom_3->identity << endl;
cout << "Atom 3 by vec " << atom_vec[5].x << "\t" << atom_vec[5].y << "\t" << atom_vec[5].z << "\t" << atom_vec[5].identity << endl;
cout << "-------------" << endl;
*/
//Finally bring the 3 atom of plane i z componet to zero so now 3 atoms lie in the xy plane
a = p.patom_3->z * p.patom_3->z;
b = p.patom_3->y * p.patom_3->y;
a = sqrt(a);
b = sqrt(b);
temp = a/b;
if( p.patom_3->y > 0 && p.patom_3->z > 0 )
{
//cout << "no change (+y,+z)" << endl;
angleC = atan(temp);
//angleC = 360*DEGTORAD - (180*DEGTORAD + angleC);
}
if( p.patom_3->y > 0 && p.patom_3->z < 0 )
{
//cout << " -1*angleC (+y,-z)" << endl;
angleC = atan(temp);
angleC = -1*angleC;
}
if( p.patom_3->y < 0 && p.patom_3->z < 0 )
{
//cout << "no change (-y,-z)" << endl;
angleC = atan(temp);
//angleC = 360*DEGTORAD + angleC;
}
if( p.patom_3->y < 0 && p.patom_3->z > 0 )
{
//cout << "-1 * angleC (-y,+z)" << endl;
angleC = atan(temp);
angleC = -1* angleC;
}
if( p.patom_3->z == 0 )
{
//cout << "ZERO atom_3 x rotation" << endl;
angleC = 0;
}
//cout << "Before" << endl;
//cout << "y = " << p.patom_3->y << " z = " << p.patom_3->z << endl;
rotate_x_axis(angleC); //Preform the rotation
//DO YOU REMEBER WHY YOU DID ALL THE ABOVE BEN, I THINK NOT
//cout << "After" << endl;
//cout << "y = " << p.patom_3->y << " z = " << p.patom_3->z << endl;
//cout << endl;
//Ok plane is now orientated by to x,y plane any atoms lying above and below z axis make this plane interior
/*
cout << "Atom 1 " << p.patom_1->x << "\t" << p.patom_1->y << "\t" << p.patom_1->z << endl;
cout << "Atom 2 " << p.patom_2->x << "\t" << p.patom_2->y << "\t" << p.patom_2->z << endl;
cout << "Atom 3 " << p.patom_3->x << "\t" << p.patom_3->y << "\t" << p.patom_3->z << endl;
cout << "Atom 3 id" << p.patom_3->identity << endl;
cout << "Atom 3 by vec " << atom_vec[5].x << "\t" << atom_vec[5].y << "\t" << atom_vec[5].z << "\t" << atom_vec[5].identity << endl;