-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelectrode.cpp
193 lines (173 loc) · 7.98 KB
/
electrode.cpp
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
//electrode.cpp
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include "molecule.h"
#include "transform.h"
#include "electrode.h"
void Electrode::JuncLocate(Molecule& examMole, int& atom1, int& atom2)
{
short int ithJunc = 0;
atom1 = 0;
atom2 = 0;
for (int i=0;i<examMole.GetAtomCount();i++)
{
if (examMole.GetAtomSym(i) == "S" && ithJunc == 0){atom1 = i; ithJunc++;}
else if (examMole.GetAtomSym(i) == "S" && ithJunc == 1){atom2 = i;}
}
return;
}
int Electrode::NearestH(Molecule& examMole, int ithAtom, char Decision)
{
double atom1x = examMole.GetAtomCoord(ithAtom, 'x');
double atom1y = examMole.GetAtomCoord(ithAtom, 'y');
double atom1z = examMole.GetAtomCoord(ithAtom, 'z');
double atom2x, atom2y, atom2z;
double NearestDist = 0.0;
double Dist;
int NearHnum;
for (int i=0;i<examMole.GetAtomCount();i++)
{
if (examMole.GetAtomSym(i) == "H")
{
atom2x = examMole.GetAtomCoord(i,'x');
atom2y = examMole.GetAtomCoord(i,'y');
atom2z = examMole.GetAtomCoord(i,'z');
Dist = sqrt(pow(atom2x-atom1x,2.0)+pow(atom2y-atom1y,2.0)+pow(atom2z-atom1z,2.0));
if (NearestDist == 0.0) { NearestDist = Dist; NearHnum = i;}
if (NearestDist > Dist) { NearestDist = Dist; NearHnum = i;}
}
}
if (Decision == 'r'){examMole.RemoveAtom(NearHnum); return 0;}
if (Decision == 'f'){return NearHnum;}
}
//EDITING THIS FOR DNA MOLECULE
void Electrode::LinearElectrode(Molecule& examMole, int MCount, std::string MType, int * juncAtoms, double BL1, double BL2, bool HydroRep)
{
std::cout << "\ndebugging\n";
int junc1 = *juncAtoms; int junc2 = *(juncAtoms+2);
int Hydro1 = *(juncAtoms+1); int Hydro2 = *(juncAtoms+3);
std::cout << "\nworking on " << junc1 << junc2 << Hydro1 << Hydro2 << "\n";
transformer.AlignAxis(examMole,'z',junc1,junc2);
const double junc1coord = examMole.GetAtomCoord(junc1,'z');
const double junc2coord = examMole.GetAtomCoord(junc2,'z');
examMole.AddAtom(MType,0.0,0.0,junc1coord-BL1);
examMole.AddAtom(MType,0.0,0.0,junc2coord+BL1);
for (int i = 2; i <= MCount; i++)
{
examMole.AddAtom(MType,0.0,0.0,junc1coord-BL1-(BL2*(i-1)));
examMole.AddAtom(MType,0.0,0.0,junc2coord+BL1+(BL2*(i-1)));
}
if (HydroRep)
{
if (Hydro2 > Hydro1) {examMole.RemoveAtom(Hydro2); examMole.RemoveAtom(Hydro1);}
else {examMole.RemoveAtom(Hydro1); examMole.RemoveAtom(Hydro2);}
}
return;
}
void Electrode::HydroRepElectrode(Molecule& examMole, int MCount, std::string MType, int * juncAtoms, double BL1, double BL2)
{
int junc1 = *juncAtoms; int junc2 = *(juncAtoms+2);
int Hydro1 = *(juncAtoms+1); int Hydro2 = *(juncAtoms+3);
transformer.AlignAxis(examMole,'z',junc1,junc2);
double S1x = examMole.GetAtomCoord(junc1,'x'); double S1y = examMole.GetAtomCoord(junc1,'y'); double S1z = examMole.GetAtomCoord(junc1,'z');
double H1x = examMole.GetAtomCoord(Hydro1,'x'); double H1y = examMole.GetAtomCoord(Hydro1,'y'); double H1z = examMole.GetAtomCoord(Hydro1,'z');
double SCoeff1 = BL1/sqrt(pow(S1x-H1x,2.0)+pow(S1y-H1y,2.0)+pow(S1z-H1z,2.0));
double Au1x = SCoeff1*(H1x-S1x)+S1x; double Au1y = SCoeff1*(H1y-S1y)+S1y; double Au1z = SCoeff1*(H1z-S1z)+S1z;
double S2x = examMole.GetAtomCoord(junc2,'x'); double S2y = examMole.GetAtomCoord(junc2,'y'); double S2z = examMole.GetAtomCoord(junc2,'z');
double H2x = examMole.GetAtomCoord(Hydro2,'x'); double H2y = examMole.GetAtomCoord(Hydro2,'y'); double H2z = examMole.GetAtomCoord(Hydro2,'z');
double SCoeff2 = BL1/sqrt(pow(S2x-H2x,2.0)+pow(S2y-H2y,2.0)+pow(S2z-H2z,2.0));
double Au2x = SCoeff2*(H2x-S2x)+S2x; double Au2y = SCoeff2*(H2y-S2y)+S2y; double Au2z = SCoeff2*(H2z-S2z)+S2z;
examMole.AddAtom(MType,Au1x,Au1y,Au1z);
examMole.AddAtom(MType,Au2x,Au2y,Au2z);
for (int i = 2; i<= MCount; i++){ examMole.AddAtom(MType,Au1x,Au1y,Au1z-(BL2*(i-1))); examMole.AddAtom(MType,Au2x,Au2y,Au2z+(BL2*(i-1))); }
if (Hydro2 > Hydro1) {examMole.RemoveAtom(Hydro2); examMole.RemoveAtom(Hydro1);}
else {examMole.RemoveAtom(Hydro1); examMole.RemoveAtom(Hydro2);}
return;
}
void Electrode::TipSquareElectrode(Molecule& examMole, std::string MType, int * juncAtoms, double BL1, double BL2)
{
int junc1 = *juncAtoms; int junc2 = *(juncAtoms+1);
int Hydro1 = *(juncAtoms+2); int Hydro2 = *(juncAtoms+3);
transformer.AlignAxis(examMole,'z',junc1,junc2);
double S2D = examMole.GetAtomCoord(junc2,'z');
examMole.AddAtom(MType,0.0,0.0,-BL1);
examMole.AddAtom(MType,BL2/2.0,BL2/2.0,-BL1-(BL2/pow(2.0,0.5)));
examMole.AddAtom(MType,-BL2/2.0,BL2/2.0,-BL1-(BL2/pow(2.0,0.5)));
examMole.AddAtom(MType,BL2/2.0,-BL2/2.0,-BL1-(BL2/pow(2.0,0.5)));
examMole.AddAtom(MType,-BL2/2.0,-BL2/2.0,-BL1-(BL2/pow(2.0,0.5)));
examMole.AddAtom(MType,0.0,0.0,BL1+S2D);
examMole.AddAtom(MType,BL2/2.0,BL2/2.0,BL1+(BL2/pow(2.0,0.5)+S2D));
examMole.AddAtom(MType,-BL2/2.0,BL2/2.0,BL1+(BL2/pow(2.0,0.5)+S2D));
examMole.AddAtom(MType,BL2/2.0,-BL2/2.0,BL1+(BL2/pow(2.0,0.5)+S2D));
examMole.AddAtom(MType,-BL2/2.0,-BL2/2.0,BL1+(BL2/pow(2.0,0.5)+S2D));
if (Hydro2 > Hydro1) {examMole.RemoveAtom(Hydro2); examMole.RemoveAtom(Hydro1);}
else {examMole.RemoveAtom(Hydro1); examMole.RemoveAtom(Hydro2);}
return;
}
void Electrode::PyramidElectrode(Molecule& examMole, int layers, std::string MType, int * juncAtoms, double BL1, double BL2)
{
const double V1 = pow(3.0,0.5)/3.0; const double V2 = pow(2.0/3.0,0.5); const double V3 = pow(3.0,0.5)/2.0;
int junc1 = *juncAtoms; int junc2 = *(juncAtoms+1);
int Hydro1 = *(juncAtoms+2); int Hydro2 = *(juncAtoms+3);
transformer.AlignAxis(examMole,'z',junc1,junc2);
double S2D = examMole.GetAtomCoord(junc2,'z');
for (int i=1; i<=layers; i++)
{
examMole.AddAtom(MType,0.0,(i-1)*BL2*V1,-(i-1)*BL2*V2-BL1);
for (int j=1; j<i; j++)
{
examMole.AddAtom(MType,j*0.5*BL2,(i-1)*BL2*V1-j*BL2*V3,-(i-1)*BL2*V2-BL1);
for (int k=1; k<=j; k++)
{
examMole.AddAtom(MType,j*0.5*BL2-BL2*k,(i-1)*BL2*V1-j*BL2*V3,-(i-1)*BL2*V2-BL1);
}
}
}
for (int i=1; i<=layers; i++)
{
examMole.AddAtom(MType,0.0,(i-1)*BL2*V1,(i-1)*BL2*V2+BL1+S2D);
for (int j=1; j<i; j++)
{
examMole.AddAtom(MType,j*0.5*BL2,(i-1)*BL2*V1-j*BL2*V3,(i-1)*BL2*V2+BL1+S2D);
for (int k=1; k<=j; k++)
{
examMole.AddAtom(MType,j*0.5*BL2-BL2*k,(i-1)*BL2*V1-j*BL2*V3,(i-1)*BL2*V2+BL1+S2D);
}
}
}
if (Hydro2 > Hydro1) {examMole.RemoveAtom(Hydro2); examMole.RemoveAtom(Hydro1);}
else {examMole.RemoveAtom(Hydro1); examMole.RemoveAtom(Hydro2);}
return;
}
void Electrode::CustomElectrode(Molecule& elecMole, Molecule& juncMole, int * juncEle, double BL)
{
int junc1 = *juncEle; int junc2 = *(juncEle+1);
int ele1 = *(juncEle+2); int aliJunc1 = *(juncEle+3);
int aliJunc2 = *(juncEle+4); int aliEle1 = *(juncEle+5);
int aliEle2 = *(juncEle+6);
transformer.AlignAxis(elecMole, 'x', aliEle1, aliEle2);
transformer.AlignAxis(juncMole, 'x', aliJunc1, aliJunc2);
for (int i=0; i<elecMole.GetAtomCount(); i++)
{
juncMole.AddAtom(elecMole.GetAtomSym(i),-elecMole.GetAtomCoord(i, 'x') - BL,elecMole.GetAtomCoord(i,'y'),elecMole.GetAtomCoord(i,'z'));
juncMole.AddAtom(elecMole.GetAtomSym(i),elecMole.GetAtomCoord(i, 'x') + juncMole.GetAtomCoord(junc2, 'x') + BL,elecMole.GetAtomCoord(i,'y'),elecMole.GetAtomCoord(i,'z'));
}
}
void Electrode::AddCustomElectrode(Molecule& elecMole, Molecule& juncMole, Molecule& elecMole2, int * juncEle, double BL)
{
int junc1 = *juncEle; int junc2= *(juncEle+1);
int ele1 = *(juncEle+2); int ele2= *(juncEle+3);
int aliJunc1 = *(juncEle+4); int aliJunc2= *(juncEle+5);
int aliEle1 = *(juncEle+6); int aliEle2 = *(juncEle+7);
int aliEle3 = *(juncEle+8); int aliEle4 = *(juncEle+9);
transformer.AlignAxis(elecMole, 'x', aliEle1, aliEle2);
transformer.AlignAxis(juncMole, 'x', aliJunc1, aliJunc2);
transformer.AlignAxis(elecMole2, 'x', aliEle3, aliEle4);
for(int i=0; i<elecMole.GetAtomCount(); i++)
{
juncMole.AddAtom(elecMole.GetAtomSym(i),-elecMole.GetAtomCoord(i,'x') - BL, elecMole.GetAtomCoord(i,'y'),elecMole.GetAtomCoord(i,'z'));
juncMole.AddAtom(elecMole2.GetAtomSym(i),elecMole2.GetAtomCoord(i,'x') + juncMole.GetAtomCoord(junc2, 'x') + BL, elecMole2.GetAtomCoord(i,'y'), elecMole2.GetAtomCoord(i,'z'));
}
}