2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2019,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.
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.
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.
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.
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.
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.
35 """Configuration and fixtures for pytest."""
42 pytest_plugins = ('gmxapi.testsupport',)
44 @pytest.fixture(scope='class')
45 def spc_water_box(gmxcli, remove_tempdir):
46 """Provide a TPR input file for a simple simulation.
48 Prepare the MD input in a freshly created working directory.
51 # TODO: Remove this import when the the spc_water_box fixture is migrated to gmxapi.testsupport
52 from gmxapi.testsupport import _cleandir
54 # TODO: (#2896) Fetch MD input from package / library data.
56 # import pkg_resources
57 # # Note: importing pkg_resources means setuptools is required for running this test.
58 # # Get or build TPR file from data bundled via setup(package_data=...)
59 # # Ref https://setuptools.readthedocs.io/en/latest/setuptools.html#including-data-files
60 # from gmx.data import tprfilename
62 with _cleandir(remove_tempdir) as tempdir:
64 testdir = os.path.dirname(__file__)
65 with open(os.path.join(testdir, 'testdata.json'), 'r') as fh:
66 testdata = json.load(fh)
68 # TODO: (#2756) Don't rely on so many automagical behaviors (as described in comments below)
70 structurefile = os.path.join(tempdir, 'structure.gro')
71 # We let `gmx solvate` use the default solvent. Otherwise, we would do
72 # gro_input = testdata['solvent_structure']
73 # with open(structurefile, 'w') as fh:
74 # fh.write('\n'.join(gro_input))
77 topfile = os.path.join(tempdir, 'topology.top')
78 top_input = testdata['solvent_topology']
79 # `gmx solvate` will append a line to the provided file with the molecule count,
80 # so we strip the last line from the input topology.
81 with open(topfile, 'w') as fh:
82 fh.write('\n'.join(top_input[:-1]))
85 assert os.path.exists(topfile)
86 solvate = gmx.commandline_operation(gmxcli,
87 arguments=['solvate', '-box', '5', '5', '5'],
88 # We use the default solvent instead of specifying one.
89 # input_files={'-cs': structurefile},
90 output_files={'-p': topfile,
94 assert os.path.exists(topfile)
96 if solvate.output.returncode.result() != 0:
97 logging.debug(solvate.output.stderr.result())
98 raise RuntimeError('solvate failed in spc_water_box testing fixture.')
100 # Choose an exactly representable dt of 2^-9 ps (approximately 0.002)
102 mdp_input = [('integrator', 'md'),
104 ('cutoff-scheme', 'Verlet'),
109 ('tcoupl', 'v-rescale'),
110 ('tc-grps', 'System'),
113 mdp_input = '\n'.join([' = '.join([str(item) for item in kvpair]) for kvpair in mdp_input])
114 mdpfile = os.path.join(tempdir, 'md.mdp')
115 with open(mdpfile, 'w') as fh:
118 tprfile = os.path.join(tempdir, 'topol.tpr')
119 # We don't use mdout_mdp, but if we don't specify it to grompp,
120 # it will be created in the current working directory.
121 mdout_mdp = os.path.join(tempdir, 'mdout.mdp')
123 grompp = gmx.commandline_operation(gmxcli, 'grompp',
126 '-p': solvate.output.file['-p'],
127 '-c': solvate.output.file['-o'],
130 output_files={'-o': tprfile})
131 tprfilename = grompp.output.file['-o'].result()
132 if grompp.output.returncode.result() != 0:
133 logging.debug(grompp.output.stderr.result())
134 raise RuntimeError('grompp failed in spc_water_box testing fixture.')
136 # TODO: more inspection of grompp errors...
137 assert os.path.exists(tprfilename)