-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxatom.cpp
More file actions
134 lines (111 loc) · 2.52 KB
/
Copy pathxatom.cpp
File metadata and controls
134 lines (111 loc) · 2.52 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
#include "xatom.h"
#include "matrix3.h"
XAtom::XAtom(Cell* c, std::string nm, int zn, double xx, double yy, double zz,
double s, double u11, double u22, double u33, double u23,
double u13, double u12, int pn, int rn) : Atom(nm,zn)
{
Uij[0]=u11; Uij[1]=u22; Uij[2]=u33;
Uij[3]=u23; Uij[4]=u13; Uij[5]=u12;
sof=s;
xf=xx; yf=yy; zf=zz;
orthogonalized=false;
cell=c;
partnum=pn;
resnum=rn;
orthogonalize(); //ensure Cartesian coordinates are updated
}
XAtom::~XAtom()
{
}
// updates the fractional coordinates from the orthogonal ones
// needed for overridden Atom methods to work
bool XAtom::deorthogonalize()
{
if (!cell)
{
xf=xo; yf=yo; zf=zo;
return false;
}
Matrix3 OM=cell->orthmat();
Matrix3 DM=inverse(OM);
Vector3 o(xo,yo,zo);
Vector3 f=DM*o;
xf=f(1); yf=f(2); zf=f(3);
return true;
}
// update Atom's Cartesian coordinates from XAtom's fractional
bool XAtom::orthogonalize()
{
Matrix3 OM;
Vector3 o;
Vector3 f;
if (orthogonalized) return true;
if (!cell)
{
xo=xf; yo=yf; zo=zf;
return false;
}
OM=cell->orthmat();
f=Vector3(xf,yf,zf);
o=OM*f;
xo=o(1); yo=o(2); zo=o(3);
orthogonalized=true;
return true;
}
double XAtom::Uiso() const
{
Matrix3 Q,D,U;
if (!cell) return -1.0;
D=Matrix3(cell->astar(),cell->bstar(),cell->cstar());
Q=cell->orthmat()*D;
U=Matrix3(Uij[0],Uij[5],Uij[4],Uij[5],Uij[1],Uij[3],Uij[4],
Uij[3],Uij[2]);
D=Q*U*transpose(Q);
return (D(1,1)+D(2,2)+D(3,3))/3.0;
}
void XAtom::coordinates(double &x, double &y, double &z) const
{
x=xf; y=yf; z=zf;
}
double XAtom::occupancy() const
{
return sof;
}
int XAtom::part() const
{
return partnum;
}
int XAtom::residue() const
{
return resnum;
}
Matrix3 XAtom::U() const
{
Matrix3 m(Uij[0],Uij[5],Uij[4],Uij[5],Uij[1],Uij[3],Uij[4],Uij[3],Uij[2]);
return m;
}
XAtom operator * (const Symmetry& s, const XAtom& xatom)
{
Matrix3 umat;
Vector3 pos;
umat=Matrix3(xatom.Uij[0],xatom.Uij[5],xatom.Uij[4],xatom.Uij[5],
xatom.Uij[1],xatom.Uij[3],xatom.Uij[4],xatom.Uij[3],
xatom.Uij[2]);
pos=Vector3(xatom.xf,xatom.yf,xatom.zf);
umat=transform_contra(s,umat);
pos=s*pos;
return XAtom(xatom.cell,xatom.label(),xatom.Z(),pos(1),pos(2),pos(3),
xatom.sof,umat(1,1),umat(2,2),umat(3,3),umat(2,3),
umat(1,3),umat(1,2),xatom.partnum,xatom.resnum);
}
// these reimplement Atom methods, keeping fractional/cartesian coords in sync
void XAtom::move_to(double x, double y, double z)
{
xo=x; yo=y; zo=z;
deorthogonalize();
}
void XAtom::move_by(double dx, double dy, double dz)
{
xo+=dx; yo+=dy; zo+=dz;
deorthogonalize();
}