f4d4dace63793ba93cbabe707bb41e9355d51bf4
[alexxy/gromacs.git] / api / nblib / tests / testsystems.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2020, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*! \internal \file
36  * \brief
37  * This implements basic nblib test systems
38  *
39  * \author Victor Holanda <victor.holanda@cscs.ch>
40  * \author Joe Jordan <ejjordan@kth.se>
41  * \author Prashanth Kanduri <kanduri@cscs.ch>
42  * \author Sebastian Keller <keller@cscs.ch>
43  * \author Artem Zhmurov <zhmurov@gmail.com>
44  */
45 #ifndef NBLIB_TESTSYSTEMS_H
46 #define NBLIB_TESTSYSTEMS_H
47
48 #include <cmath>
49
50 #include "nblib/box.h"
51 #include "nblib/molecules.h"
52 #include "nblib/particletype.h"
53 #include "nblib/simulationstate.h"
54 #include "nblib/topology.h"
55
56 namespace nblib
57 {
58
59 //! \internal \brief Parameters from gromos43A1
60 struct ArAtom
61 {
62     //! Argon Particle Name
63     ParticleName particleName = ParticleName("Ar");
64     //! Argon particle type name
65     ParticleTypeName particleTypeName = ParticleTypeName("Ar");
66     //! Argon molecule name
67     MoleculeName moleculeName = MoleculeName("Ar");
68     //! Argon Particle Mass
69     Mass mass = Mass(39.94800);
70     //! Argon C6 parameter
71     C6 c6{ 0.0062647225 };
72     //! Argon C12 parameter
73     C12 c12{ 9.847044e-06 };
74 };
75
76 //! Lookup table for charges needed for building topologies
77 extern std::unordered_map<std::string, Charge> Charges;
78
79 //! \internal \brief Make an SPC water molecule with parameters from gromos43A1
80 class WaterMoleculeBuilder
81 {
82 public:
83     // There is no default ctor for a Molecule so it must be initialized
84     WaterMoleculeBuilder();
85
86     //! Return the initialized water Molecule, with exclusions
87     Molecule waterMolecule();
88
89     //! Return the initialized water Molecule, without exclusions
90     Molecule waterMoleculeWithoutExclusions();
91
92 private:
93     //! The molecule
94     Molecule water_;
95
96     //! Add the exclusions from particle names. Private to prevent multiple calls
97     void addExclusionsFromNames();
98 };
99
100 //! \internal \brief Make a methanol molecule with parameters from gromos43A1
101 class MethanolMoleculeBuilder
102 {
103 public:
104     // There is no default ctor for a Molecule so it must be initialized
105     MethanolMoleculeBuilder();
106
107     //! Return the initialized water Molecule, with exclusions
108     Molecule methanolMolecule();
109
110 private:
111     //! The molecule
112     Molecule methanol_;
113 };
114
115 //! \internal \brief Build topology of water molecules of a specified number
116 class WaterTopologyBuilder
117 {
118 public:
119     //! Return a topology with specified SPC water molecules
120     Topology buildTopology(int numMolecules);
121
122     //! Return the actual water Molecule used in the topology
123     Molecule water();
124
125 private:
126     WaterMoleculeBuilder waterMolecule_;
127 };
128
129 //! \internal \brief Build topology of methanol+water molecules from specified numbers
130 class SpcMethanolTopologyBuilder
131 {
132 public:
133     //! Return a topology with specified methanol molecules
134     Topology buildTopology(int numWater, int numMethanol);
135
136     //! Return the actual methanol Molecule used in the topology
137     Molecule methanol();
138
139     //! Return the actual water Molecule used in the topology
140     Molecule water();
141
142 private:
143     MethanolMoleculeBuilder methanolMolecule_;
144     WaterMoleculeBuilder    waterMolecule_;
145 };
146
147 //! \internal \brief Build topology of argon molecules of a specified number
148 class ArgonTopologyBuilder
149 {
150 public:
151     //! Build a topology with specified argon molecules
152     ArgonTopologyBuilder(const int& numParticles);
153
154     //! Get the topology with specified argon molecules
155     Topology argonTopology();
156
157 private:
158     TopologyBuilder topologyBuilder_;
159 };
160
161 //! \internal \brief Build simulation state for the argon example
162 class ArgonSimulationStateBuilder
163 {
164 public:
165     ArgonSimulationStateBuilder();
166
167     //! Set coordinates of particles in the defined system
168     void setCoordinate(int particleNum, int dimension, real value);
169
170     //! Set particle velocities
171     void setVelocity(int particleNum, int dimension, real value);
172
173     //! Setup simulation state
174     SimulationState setupSimulationState();
175
176     //! Get the topology
177     const Topology& topology() const;
178
179     //! Get the box bounding the system
180     Box& box();
181
182     //! Get current coordinates
183     std::vector<Vec3>& coordinates();
184
185     //! Get current velocities
186     std::vector<Vec3>& velocities();
187
188 private:
189     std::vector<Vec3> coordinates_;
190     std::vector<Vec3> velocities_;
191     std::vector<Vec3> forces_;
192
193     Box      box_;
194     Topology topology_;
195 };
196
197 //! \internal \brief Build simulation state for the SPC-Methanol example
198 class SpcMethanolSimulationStateBuilder
199 {
200 public:
201     SpcMethanolSimulationStateBuilder();
202
203     //! Setup simulation state
204     SimulationState setupSimulationState();
205
206     //! Get current coordinates
207     std::vector<Vec3>& coordinates();
208
209     //! Get current velocities
210     std::vector<Vec3>& velocities();
211
212 private:
213     std::vector<Vec3> coordinates_;
214     std::vector<Vec3> velocities_;
215     std::vector<Vec3> forces_;
216
217     Box      box_;
218     Topology topology_;
219 };
220
221 } // namespace nblib
222 #endif // NBLIB_TESTSYSTEMS_H