OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
Restraint.hpp
Go to the documentation of this file.
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/**
49 * @file Restraint.hpp
50 * @author cli2
51 * @date 06/17/2009
52 * @version 1.0
53 */
54
55#ifndef RESTRAINTS_RESTRAINT_HPP
56#define RESTRAINTS_RESTRAINT_HPP
57
58#include <config.h>
59
60#include <map>
61
62#include "math/Vector3.hpp"
63#include "utils/GenericData.hpp"
64
65namespace OpenMD {
66
67 class Restraint {
68 public:
69 enum {
70 rtDisplacement = 1,
71 rtDisplacementX = 2,
72 rtDisplacementY = 4,
73 rtDisplacementZ = 8,
74 rtAbsoluteZ = 16,
75 rtTwist = 32,
76 rtSwingX = 64,
77 rtSwingY = 128
78 };
79
80 using RealPair = std::pair<RealType, RealType>;
81
82 Restraint() :
83 twist0_(0.0), swingX0_(0.0), swingY0_(0.0), posZ0_(0.0),
84 printRest_(false), restType_(0) {}
85
86 virtual ~Restraint() {}
87
88 // these are place-holders. The subclasses will have different arguments
89 // to the two functions.
90 void calcForce() {}
91 void setReferenceStructure() {}
92
93 RealType getUnscaledPotential() { return pot_; }
94 RealType getPotential() { return scaleFactor_ * pot_; }
95
96 void setRestraintName(std::string name) { restName_ = name; }
97 std::string getRestraintName() { return restName_; }
98
99 /** Returns the restraint type */
100 int getRestraintType() { return restType_; }
101 /** Sets the restraint type */
102 void setRestraintType(int restType) { restType_ = restType; }
103
104 void setScaleFactor(RealType sf) { scaleFactor_ = sf; }
105
106 void setDisplacementForceConstant(RealType kDisp) {
107 kDisp_ = kDisp;
108 restType_ |= rtDisplacement;
109 if (printRest_) restInfo_[rtDisplacement] = std::make_pair(0.0, 0.0);
110 }
111
112 void setDisplacementXForceConstant(RealType kDisp) {
113 kDispX_ = kDisp;
114 restType_ |= rtDisplacementX;
115 if (printRest_) restInfo_[rtDisplacementX] = std::make_pair(0.0, 0.0);
116 }
117 void setDisplacementYForceConstant(RealType kDisp) {
118 kDispY_ = kDisp;
119 restType_ |= rtDisplacementY;
120 if (printRest_) restInfo_[rtDisplacementY] = std::make_pair(0.0, 0.0);
121 }
122 void setDisplacementZForceConstant(RealType kDisp) {
123 kDispZ_ = kDisp;
124 restType_ |= rtDisplacementZ;
125 if (printRest_) restInfo_[rtDisplacementZ] = std::make_pair(0.0, 0.0);
126 }
127
128 void setAbsoluteForceConstant(RealType kAbs) {
129 kAbs_ = kAbs;
130 restType_ |= rtAbsoluteZ;
131 if (printRest_) restInfo_[rtAbsoluteZ] = std::make_pair(0.0, 0.0);
132 }
133
134 void setTwistForceConstant(RealType kTwist) {
135 kTwist_ = kTwist / 4;
136 restType_ |= rtTwist;
137 if (printRest_) restInfo_[rtTwist] = std::make_pair(0.0, 0.0);
138 }
139
140 void setSwingXForceConstant(RealType kSwingX) {
141 kSwingX_ = kSwingX;
142 restType_ |= rtSwingX;
143 if (printRest_) restInfo_[rtSwingX] = std::make_pair(0.0, 0.0);
144 }
145
146 void setSwingYForceConstant(RealType kSwingY) {
147 kSwingY_ = kSwingY;
148 restType_ |= rtSwingY;
149 if (printRest_) restInfo_[rtSwingY] = std::make_pair(0.0, 0.0);
150 }
151
152 void setAbsolutePositionZ(RealType z0) {
153 posZ0_ = z0;
154 restType_ |= rtAbsoluteZ;
155 if (printRest_) restInfo_[rtAbsoluteZ] = std::make_pair(0.0, 0.0);
156 }
157
158 /* restraint angles are measured relative to the ideal structure,
159 and are measured in radians. If you want to restrain to the
160 same structure as the ideal structure, these do not need to be set.
161 */
162 void setRestrainedTwistAngle(RealType twist0) {
163 twist0_ = twist0;
164 restType_ |= rtTwist;
165 if (printRest_) restInfo_[rtTwist] = std::make_pair(0.0, 0.0);
166 }
167
168 void setRestrainedSwingXAngle(RealType swingX0) {
169 swingX0_ = swingX0;
170 restType_ |= rtSwingX;
171 if (printRest_) restInfo_[rtSwingX] = std::make_pair(0.0, 0.0);
172 }
173
174 void setRestrainedSwingYAngle(RealType swingY0) {
175 swingY0_ = swingY0;
176 restType_ |= rtSwingY;
177 if (printRest_) restInfo_[rtSwingY] = std::make_pair(0.0, 0.0);
178 }
179
180 void setPrintRestraint(bool printRest) { printRest_ = printRest; }
181
182 RealType getDisplacementForceConstant() { return kDisp_; }
183 RealType getDisplacementXForceConstant() { return kDispX_; }
184 RealType getDisplacementYForceConstant() { return kDispY_; }
185 RealType getDisplacementZForceConstant() { return kDispZ_; }
186 RealType getAbsoluteForceConstant() { return kAbs_; }
187 RealType getAbsolutePositionZ() { return posZ0_; }
188 RealType getTwistForceConstant() { return kTwist_; }
189 RealType getSwingXForceConstant() { return kSwingX_; }
190 RealType getSwingYForceConstant() { return kSwingY_; }
191 RealType getRestrainedTwistAngle() { return twist0_; }
192 RealType getRestrainedSwingXAngle() { return swingX0_; }
193 RealType getRestrainedSwingYAngle() { return swingY0_; }
194 std::map<int, RealPair> getRestraintInfo() { return restInfo_; }
195 bool getPrintRestraint() { return printRest_; }
196
197 protected:
198 RealType scaleFactor_;
199 RealType kDisp_;
200 RealType kDispX_;
201 RealType kDispY_;
202 RealType kDispZ_;
203 RealType kAbs_;
204 RealType kTwist_;
205 RealType kSwingX_;
206 RealType kSwingY_;
207 RealType pot_;
208 RealType twist0_;
209 RealType swingX0_;
210 RealType swingY0_;
211 RealType posZ0_;
212 bool printRest_;
213
214 int restType_;
215 std::string restName_;
216 std::map<int, RealPair> restInfo_;
217 };
218
219 using RestraintData = SimpleTypeData<Restraint*>;
220} // namespace OpenMD
221
222#endif
void setRestraintType(int restType)
Sets the restraint type.
int getRestraintType()
Returns the restraint type.
SimpleTypeData class is a POD repository class.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.