OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
HullFinder.cpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#include "selection/HullFinder.hpp"
46
47#include "math/AlphaHull.hpp"
48#include "math/ConvexHull.hpp"
50
51namespace OpenMD {
52
53 HullFinder::HullFinder(SimInfo* info) : info_(info) {
54 nObjects_.push_back(info_->getNGlobalAtoms() +
55 info_->getNGlobalRigidBodies());
56 nObjects_.push_back(info_->getNGlobalBonds());
57 nObjects_.push_back(info_->getNGlobalBends());
58 nObjects_.push_back(info_->getNGlobalTorsions());
59 nObjects_.push_back(info_->getNGlobalInversions());
60 nObjects_.push_back(info_->getNGlobalMolecules());
61
62 stuntdoubles_.resize(nObjects_[STUNTDOUBLE]);
63 bonds_.resize(nObjects_[BOND]);
64 bends_.resize(nObjects_[BEND]);
65 torsions_.resize(nObjects_[TORSION]);
66 inversions_.resize(nObjects_[INVERSION]);
67 molecules_.resize(nObjects_[MOLECULE]);
68
69 SimInfo::MoleculeIterator mi;
70 Molecule::IntegrableObjectIterator ioi;
71 Molecule::AtomIterator ai;
72 Molecule::RigidBodyIterator rbIter;
73 Molecule::BondIterator bondIter;
74 Molecule::BendIterator bendIter;
75 Molecule::TorsionIterator torsionIter;
76 Molecule::InversionIterator inversionIter;
77
78 Molecule* mol;
79 StuntDouble* sd;
80 Atom* atom;
81 RigidBody* rb;
82 Bond* bond;
83 Bend* bend;
84 Torsion* torsion;
85 Inversion* inversion;
86
87 for (mol = info_->beginMolecule(mi); mol != NULL;
88 mol = info_->nextMolecule(mi)) {
89 molecules_[mol->getGlobalIndex()] = mol;
90
91 // Hull is constructed from all known integrable objects.
92 for (sd = mol->beginIntegrableObject(ioi); sd != NULL;
93 sd = mol->nextIntegrableObject(ioi)) {
94 localSites_.push_back(sd);
95 }
96
97 // selection can include atoms (which may be a subset of the IOs)
98 for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
99 stuntdoubles_[atom->getGlobalIndex()] = atom;
100 }
101
102 // and rigid bodies
103 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
104 rb = mol->nextRigidBody(rbIter)) {
105 stuntdoubles_[rb->getGlobalIndex()] = rb;
106 }
107
108 // These others are going to be inferred from the objects on the hull:
109 for (bond = mol->beginBond(bondIter); bond != NULL;
110 bond = mol->nextBond(bondIter)) {
111 bonds_[bond->getGlobalIndex()] = bond;
112 }
113 for (bend = mol->beginBend(bendIter); bend != NULL;
114 bend = mol->nextBend(bendIter)) {
115 bends_[bend->getGlobalIndex()] = bend;
116 }
117 for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
118 torsion = mol->nextTorsion(torsionIter)) {
119 torsions_[torsion->getGlobalIndex()] = torsion;
120 }
121 for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
122 inversion = mol->nextInversion(inversionIter)) {
123 inversions_[inversion->getGlobalIndex()] = inversion;
124 }
125 }
126#ifdef HAVE_QHULL
127 surfaceMesh_ = new ConvexHull();
128#endif
129 }
130
131 AlphaHullFinder::AlphaHullFinder(SimInfo* info) : HullFinder(info) {
132#ifdef HAVE_QHULL
133 delete surfaceMesh_;
134 surfaceMesh_ = new AlphaHull(0.0);
135#endif
136 }
137
138 void AlphaHullFinder::setAlpha(RealType alpha) {
139#ifdef HAVE_QHULL
140 delete surfaceMesh_;
141 surfaceMesh_ = new AlphaHull(alpha);
142#endif
143 }
144
145 HullFinder::~HullFinder() {
146#ifdef HAVE_QHULL
147 delete surfaceMesh_;
148#endif
149 }
150
151 SelectionSet HullFinder::findHull() {
152 SelectionSet ssResult(nObjects_);
153#ifdef HAVE_QHULL
154 surfaceMesh_->computeHull(localSites_);
155
156 std::vector<Triangle> sMesh = surfaceMesh_->getMesh();
157 // Loop over the mesh faces
158 std::vector<Triangle>::iterator face;
159 std::vector<StuntDouble*>::iterator vertex;
160
161 // This will work in parallel because the triangles returned by the mesh
162 // have a NULL stuntDouble if this processor doesn't own
163
164 for (face = sMesh.begin(); face != sMesh.end(); ++face) {
165 Triangle thisTriangle = *face;
166 std::vector<StuntDouble*> vertexSDs = thisTriangle.getVertices();
167 for (vertex = vertexSDs.begin(); vertex != vertexSDs.end(); ++vertex) {
168 if ((*vertex) != NULL) {
169 ssResult.bitsets_[STUNTDOUBLE].setBitOn((*vertex)->getGlobalIndex());
170 }
171 }
172 }
173 surfaceArea_ = surfaceMesh_->getArea();
174#else
175 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
176 "HullFinder : Hull calculation is not possible without libqhull.\n"
177 "\tPlease rebuild OpenMD with qhull enabled.");
178 painCave.severity = OPENMD_ERROR;
179 painCave.isFatal = 1;
180 simError();
181#endif
182
183 return ssResult;
184 }
185
186 SelectionSet HullFinder::findHull(int) {
187 SelectionSet ssResult(nObjects_);
188#ifdef HAVE_QHULL
189 surfaceMesh_->computeHull(localSites_);
190 std::vector<Triangle> sMesh = surfaceMesh_->getMesh();
191 // Loop over the mesh faces
192 std::vector<Triangle>::iterator face;
193 std::vector<StuntDouble*>::iterator vertex;
194
195 // This will work in parallel because the triangles returned by the mesh
196 // have a NULL stuntDouble if this processor doesn't own the
197
198 for (face = sMesh.begin(); face != sMesh.end(); ++face) {
199 Triangle thisTriangle = *face;
200 std::vector<StuntDouble*> vertexSDs = thisTriangle.getVertices();
201 for (vertex = vertexSDs.begin(); vertex != vertexSDs.end(); ++vertex) {
202 if ((*vertex) != NULL) {
203 ssResult.bitsets_[STUNTDOUBLE].setBitOn((*vertex)->getGlobalIndex());
204 }
205 }
206 }
207 surfaceArea_ = surfaceMesh_->getArea();
208 volume_ = surfaceMesh_->getVolume();
209
210#else
211 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
212 "HullFinder : Hull calculation is not possible without libqhull.\n"
213 "\tPlease rebuild OpenMD with qhull enabled.");
214 painCave.severity = OPENMD_ERROR;
215 painCave.isFatal = 1;
216 simError();
217#endif
218
219 return ssResult;
220 }
221} // namespace OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
@ STUNTDOUBLE
StuntDoubles (Atoms & RigidBodies)