OpenMD 3.2
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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48#include "selection/HullFinder.hpp"
49
50#include "math/AlphaHull.hpp"
51#include "math/ConvexHull.hpp"
53
54namespace OpenMD {
55
56 HullFinder::HullFinder(SimInfo* info) : info_(info) {
57 nObjects_.push_back(info_->getNGlobalAtoms() +
58 info_->getNGlobalRigidBodies());
59 nObjects_.push_back(info_->getNGlobalBonds());
60 nObjects_.push_back(info_->getNGlobalBends());
61 nObjects_.push_back(info_->getNGlobalTorsions());
62 nObjects_.push_back(info_->getNGlobalInversions());
63 nObjects_.push_back(info_->getNGlobalMolecules());
64
65 stuntdoubles_.resize(nObjects_[STUNTDOUBLE]);
66 bonds_.resize(nObjects_[BOND]);
67 bends_.resize(nObjects_[BEND]);
68 torsions_.resize(nObjects_[TORSION]);
69 inversions_.resize(nObjects_[INVERSION]);
70 molecules_.resize(nObjects_[MOLECULE]);
71
72 SimInfo::MoleculeIterator mi;
73 Molecule::IntegrableObjectIterator ioi;
74 Molecule::AtomIterator ai;
75 Molecule::RigidBodyIterator rbIter;
76 Molecule::BondIterator bondIter;
77 Molecule::BendIterator bendIter;
78 Molecule::TorsionIterator torsionIter;
79 Molecule::InversionIterator inversionIter;
80
81 Molecule* mol;
82 StuntDouble* sd;
83 Atom* atom;
84 RigidBody* rb;
85 Bond* bond;
86 Bend* bend;
87 Torsion* torsion;
88 Inversion* inversion;
89
90 for (mol = info_->beginMolecule(mi); mol != NULL;
91 mol = info_->nextMolecule(mi)) {
92 molecules_[mol->getGlobalIndex()] = mol;
93
94 for (sd = mol->beginIntegrableObject(ioi); sd != NULL;
95 sd = mol->nextIntegrableObject(ioi)) {
96 localSites_.push_back(sd);
97 }
98
99 for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
100 stuntdoubles_[atom->getGlobalIndex()] = atom;
101 }
102 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
103 rb = mol->nextRigidBody(rbIter)) {
104 stuntdoubles_[rb->getGlobalIndex()] = rb;
105 }
106 for (bond = mol->beginBond(bondIter); bond != NULL;
107 bond = mol->nextBond(bondIter)) {
108 bonds_[bond->getGlobalIndex()] = bond;
109 }
110 for (bend = mol->beginBend(bendIter); bend != NULL;
111 bend = mol->nextBend(bendIter)) {
112 bends_[bend->getGlobalIndex()] = bend;
113 }
114 for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
115 torsion = mol->nextTorsion(torsionIter)) {
116 torsions_[torsion->getGlobalIndex()] = torsion;
117 }
118 for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
119 inversion = mol->nextInversion(inversionIter)) {
120 inversions_[inversion->getGlobalIndex()] = inversion;
121 }
122 }
123#ifdef HAVE_QHULL
124 surfaceMesh_ = new ConvexHull();
125#endif
126 }
127
128 AlphaHullFinder::AlphaHullFinder(SimInfo* info) : HullFinder(info) {
129#ifdef HAVE_QHULL
130 delete surfaceMesh_;
131 surfaceMesh_ = new AlphaHull(0.0);
132#endif
133 }
134
135 void AlphaHullFinder::setAlpha(RealType alpha) {
136#ifdef HAVE_QHULL
137 delete surfaceMesh_;
138 surfaceMesh_ = new AlphaHull(alpha);
139#endif
140 }
141
142 HullFinder::~HullFinder() {
143#ifdef HAVE_QHULL
144 delete surfaceMesh_;
145#endif
146 }
147
148 SelectionSet HullFinder::findHull() { return findHullImpl(false); }
149
150 SelectionSet HullFinder::findHull(int) { return findHullImpl(true); }
151
152 SelectionSet HullFinder::findHullImpl(bool computeVolume) {
153 SelectionSet ssResult(nObjects_);
154#ifdef HAVE_QHULL
155 surfaceMesh_->computeHull(localSites_);
156
157 std::vector<Triangle> sMesh = surfaceMesh_->getMesh();
158
159 for (auto& face : sMesh) {
160 std::vector<StuntDouble*> vertexSDs = face.getVertices();
161 for (auto* vertex : vertexSDs) {
162 if (vertex != NULL) {
163 ssResult.bitsets_[STUNTDOUBLE].setBitOn(vertex->getGlobalIndex());
164 }
165 }
166 }
167 surfaceArea_ = surfaceMesh_->getArea();
168 if (computeVolume) volume_ = surfaceMesh_->getVolume();
169#else
170 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
171 "HullFinder : Hull calculation is not possible without libqhull.\n"
172 "\tPlease rebuild OpenMD with qhull enabled.");
173 painCave.severity = OPENMD_ERROR;
174 painCave.isFatal = 1;
175 simError();
176#endif
177
178 return ssResult;
179 }
180} // namespace OpenMD
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:96
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
@ STUNTDOUBLE
StuntDoubles (Atoms & RigidBodies).