OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
MoleculeStamp.hpp
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#ifndef TYPES_MOLECULESTAMP_HPP
49#define TYPES_MOLECULESTAMP_HPP
50
51#include <utility>
52#include <vector>
53
54#include "types/AtomStamp.hpp"
55#include "types/BendStamp.hpp"
56#include "types/BondStamp.hpp"
57#include "types/ConstraintStamp.hpp"
58#include "types/CutoffGroupStamp.hpp"
59#include "types/FragmentStamp.hpp"
60#include "types/InversionStamp.hpp"
61#include "types/RigidBodyStamp.hpp"
62#include "types/TorsionStamp.hpp"
63
64namespace OpenMD {
65 class MoleculeStamp : public DataHolder {
66 DeclareParameter(Name, std::string);
67 DeclareParameter(ConstrainTotalCharge, bool);
68
69 public:
70 MoleculeStamp();
71 virtual ~MoleculeStamp();
72
73 bool addAtomStamp(AtomStamp* atom);
74 bool addBondStamp(BondStamp* bond);
75 bool addBendStamp(BendStamp* bend);
76 bool addTorsionStamp(TorsionStamp* torsion);
77 bool addInversionStamp(InversionStamp* inversion);
78 bool addRigidBodyStamp(RigidBodyStamp* rigidbody);
79 bool addCutoffGroupStamp(CutoffGroupStamp* cutoffgroup);
80 bool addFragmentStamp(FragmentStamp* fragment);
81 bool addConstraintStamp(ConstraintStamp* constraint);
82
83 void setIdent(int id) { ident_ = id; }
84 int getIdent() { return ident_; }
85
86 void setRegion(int r) { region_ = r; }
87 int getRegion() { return region_; }
88
89 std::size_t getNAtoms() { return atomStamps_.size(); }
90 std::size_t getNBonds() { return bondStamps_.size(); }
91 std::size_t getNBends() { return bendStamps_.size(); }
92 std::size_t getNTorsions() { return torsionStamps_.size(); }
93 std::size_t getNInversions() { return inversionStamps_.size(); }
94 std::size_t getNRigidBodies() { return rigidBodyStamps_.size(); }
95 std::size_t getNCutoffGroups() { return cutoffGroupStamps_.size(); }
96 std::size_t getNConstraints() { return constraintStamps_.size(); }
97 int getNIntegrable() { return nintegrable_; }
98 std::size_t getNFreeAtoms() { return freeAtoms_.size(); }
99 virtual void validate();
100
101 AtomStamp* getAtomStamp(int index) { return atomStamps_[index]; }
102 BondStamp* getBondStamp(int index) { return bondStamps_[index]; }
103 BendStamp* getBendStamp(int index) { return bendStamps_[index]; }
104 TorsionStamp* getTorsionStamp(int index) { return torsionStamps_[index]; }
105 InversionStamp* getInversionStamp(int index) {
106 return inversionStamps_[index];
107 }
108 RigidBodyStamp* getRigidBodyStamp(int index) {
109 return rigidBodyStamps_[index];
110 }
111 CutoffGroupStamp* getCutoffGroupStamp(int index) {
112 return cutoffGroupStamps_[index];
113 }
114 FragmentStamp* getFragmentStamp(int index) {
115 return fragmentStamps_[index];
116 }
117 ConstraintStamp* getConstraintStamp(int index) {
118 return constraintStamps_[index];
119 }
120
121 bool isBondInSameRigidBody(BondStamp* bond);
122 bool isAtomInRigidBody(int atomIndex);
123 bool isAtomInRigidBody(int atomIndex, int& whichRigidBody,
124 int& consAtomIndex);
125 std::vector<std::pair<int, int>> getJointAtoms(int rb1, int rb2);
126
127 private:
128 void fillBondInfo();
129 void checkAtoms();
130 void checkBonds();
131 void checkBends();
132 void checkTorsions();
133 void checkInversions();
134 void checkRigidBodies();
135 void checkCutoffGroups();
136 void checkFragments();
137 void checkConstraints();
138
139 template<class Cont, class T>
140 bool addIndexSensitiveStamp(Cont& cont, T* stamp) {
141 // typename Cont::iterator i;
142 unsigned int index = stamp->getIndex();
143 bool ret = false;
144 size_t size = cont.size();
145
146 if (size >= index + 1) {
147 if (cont[index] != NULL) {
148 ret = false;
149 } else {
150 cont[index] = stamp;
151 ret = true;
152 }
153 } else {
154 cont.insert(cont.end(), index - cont.size() + 1, NULL);
155 cont[index] = stamp;
156 ret = true;
157 }
158
159 return ret;
160 }
161
162 std::vector<AtomStamp*> atomStamps_;
163 std::vector<int> freeAtoms_;
164 std::vector<BondStamp*> bondStamps_;
165 std::vector<BendStamp*> bendStamps_;
166 std::vector<TorsionStamp*> torsionStamps_;
167 std::vector<InversionStamp*> inversionStamps_;
168 std::vector<RigidBodyStamp*> rigidBodyStamps_;
169 std::vector<CutoffGroupStamp*> cutoffGroupStamps_;
170 std::vector<FragmentStamp*> fragmentStamps_;
171 std::vector<ConstraintStamp*> constraintStamps_;
172 std::vector<int> atom2Rigidbody;
173 int nintegrable_;
174 int region_;
175 int ident_;
176 };
177
179 public:
180 bool operator()(MoleculeStamp* lhs, MoleculeStamp* rhs) const {
181 return lhs->getIdent() < rhs->getIdent();
182 }
183 };
184
185 using MoleculeStampSet = std::set<MoleculeStamp*, MoleculeStampCompare>;
186} // namespace OpenMD
187
188#endif
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.