FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
libdiffpy/src/diffpy/srreal/BaseBondGenerator.cpp at develop · cfarrow/libdiffpy · GitHub
cfarrow
libdiffpy
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
libdiffpy
/
src
/
diffpy
/
srreal
/
BaseBondGenerator.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
277 lines (211 loc) · 5.89 KB
Breadcrumbs
libdiffpy
/
src
/
diffpy
/
srreal
/
BaseBondGenerator.cpp
Copy path
File metadata and controls
277 lines (211 loc) · 5.89 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
****************************************************************************
*
* diffpy.srreal by DANSE Diffraction group
* Simon J. L. Billinge
* (c) 2009 Trustees of the Columbia University
* in the City of New York. All rights reserved.
*
* File coded by: Pavol Juhas
*
* See AUTHORS.txt for a list of people who contributed.
* See LICENSE.txt for license information.
*
******************************************************************************
*
* class BaseBondGenerator -- semi-abstract class for generation
* of all atom pairs containing specified anchor atom.
*
****************************************************************************
*/
#
include
<
algorithm
>
#
include
<
diffpy/srreal/BaseBondGenerator.hpp
>
#
include
<
diffpy/srreal/StructureAdapter.hpp
>
#
include
<
diffpy/mathutils.hpp
>
using
diffpy::mathutils::eps_eq;
namespace
diffpy
{
namespace
srreal
{
//
using namespace std;
//
Constructor ---------------------------------------------------------------
BaseBondGenerator::BaseBondGenerator
(StructureAdapterConstPtr stru)
{
msite_anchor =
0
;
msite_first =
0
;
msite_last =
0
;
msite_current =
0
;
mstructure = stru;
this
->
setRmin
(
0.0
);
this
->
setRmax
(
DEFAULT_BONDGENERATOR_RMAX
);
msite_selected.
resize
(mstructure->
countSites
(),
true
);
if
(mstructure->
countSites
())
{
this
->
selectAnchorSite
(
0
);
this
->
selectSiteRange
(
0
, mstructure->
countSites
());
}
}
//
Public Methods ------------------------------------------------------------
//
loop control
void
BaseBondGenerator::rewind
()
{
msite_current = msite_first;
this
->
advanceIfSkippedSite
();
//
avoid calling rewindSymmetry at an invalid site
if
(
this
->
finished
())
return
;
this
->
rewindSymmetry
();
this
->
advanceWhileInvalid
();
}
void
BaseBondGenerator::next
()
{
this
->
getNextBond
();
this
->
advanceWhileInvalid
();
}
bool
BaseBondGenerator::finished
()
const
{
return
msite_current >= msite_last;
}
//
configuration
void
BaseBondGenerator::selectAnchorSite
(
int
anchor)
{
assert
(
0
<= anchor && anchor < mstructure->
countSites
());
msite_anchor = anchor;
mr0 = mstructure->
siteCartesianPosition
(msite_anchor);
this
->
setFinishedFlag
();
}
void
BaseBondGenerator::selectSiteRange
(
int
first,
int
last)
{
assert
(
0
<= first && first < mstructure->
countSites
());
assert
(last <= mstructure->
countSites
());
msite_first = first;
msite_last = last;
std::fill
(msite_selected.
begin
() + first,
msite_selected.
begin
() + last,
true
);
this
->
setFinishedFlag
();
}
void
BaseBondGenerator::selectSite
(
int
siteindex,
bool
select)
{
msite_selected[siteindex] = select;
}
void
BaseBondGenerator::setRmin
(
double
rmin)
{
if
(rmin != mrmin)
this
->
setFinishedFlag
();
mrmin = rmin;
}
void
BaseBondGenerator::setRmax
(
double
rmax)
{
if
(rmax != mrmax)
this
->
setFinishedFlag
();
mrmax = rmax;
}
//
data query
const
double
&
BaseBondGenerator::getRmin
()
const
{
return
mrmin;
}
const
double
&
BaseBondGenerator::getRmax
()
const
{
return
mrmax;
}
int
BaseBondGenerator::site0
()
const
{
return
msite_anchor;
}
int
BaseBondGenerator::site1
()
const
{
return
msite_current;
}
int
BaseBondGenerator::multiplicity
()
const
{
return
mstructure->
siteMultiplicity
(
this
->
site0
());
}
const
R3
::Vector&
BaseBondGenerator::r0
()
const
{
return
mr0;
}
const
R3
::Vector&
BaseBondGenerator::r1
()
const
{
return
mr1;
}
const
double
&
BaseBondGenerator::distance
()
const
{
return
mdistance;
}
const
R3
::Vector&
BaseBondGenerator::r01
()
const
{
return
mr01;
}
const
R3
::Matrix&
BaseBondGenerator::Ucartesian0
()
const
{
return
mstructure->
siteCartesianUij
(
this
->
site0
());
}
const
R3
::Matrix&
BaseBondGenerator::Ucartesian1
()
const
{
return
mstructure->
siteCartesianUij
(
this
->
site1
());
}
double
BaseBondGenerator::msd
()
const
{
static
R3
::Vector s;
s =
this
->
r01
();
double
msd0 =
meanSquareDisplacement
(
this
->
Ucartesian0
(), s,
mstructure->
siteAnisotropy
(
this
->
site0
()));
double
msd1 =
meanSquareDisplacement
(
this
->
Ucartesian1
(), s,
mstructure->
siteAnisotropy
(
this
->
site1
()));
double
rv = msd0 + msd1;
return
rv;
}
//
Protected Methods ---------------------------------------------------------
bool
BaseBondGenerator::iterateSymmetry
()
{
return
false
;
}
void
BaseBondGenerator::rewindSymmetry
()
{
mr1 = mstructure->
siteCartesianPosition
(
this
->
site1
());
this
->
updateDistance
();
}
void
BaseBondGenerator::getNextBond
()
{
if
(
this
->
iterateSymmetry
())
return
;
msite_current +=
1
;
this
->
advanceIfSkippedSite
();
//
avoid calling rewindSymmetry at an invalid site
if
(!(
this
->
finished
()))
this
->
rewindSymmetry
();
}
void
BaseBondGenerator::updateDistance
()
{
if
((mdistance =
fabs
(mr01[
0
] = mr1[
0
] - mr0[
0
])) > mrmax)
return
;
if
((mdistance =
fabs
(mr01[
1
] = mr1[
1
] - mr0[
1
])) > mrmax)
return
;
if
((mdistance =
fabs
(mr01[
2
] = mr1[
2
] - mr0[
2
])) > mrmax)
return
;
mdistance =
R3::norm
(mr01);
}
//
Private Methods -----------------------------------------------------------
void
BaseBondGenerator::advanceIfSkippedSite
()
{
while
(!
this
->
finished
() && !msite_selected[msite_current])
{
++msite_current;
}
}
void
BaseBondGenerator::advanceWhileInvalid
()
{
while
(!
this
->
finished
() &&
(
this
->
bondOutOfRange
() ||
this
->
atSelfPair
()))
{
this
->
getNextBond
();
}
}
//
Private Methods -----------------------------------------------------------
bool
BaseBondGenerator::bondOutOfRange
()
const
{
const
double
& d =
this
->
distance
();
bool
rv = (d <
this
->
getRmin
()) || (d >
this
->
getRmax
());
return
rv;
}
bool
BaseBondGenerator::atSelfPair
()
const
{
bool
rv =
eps_eq
(
this
->
distance
(),
0.0
);
return
rv;
}
void
BaseBondGenerator::setFinishedFlag
()
{
msite_current = msite_last;
}
}
//
namespace srreal
}
//
namespace diffpy
//
End of file
Back
|
FazBrowse Home
|
New Git URL