Skip to content

Commit

Permalink
ENH: Expose simulation cell dimensions in insert-molecules (#38)
Browse files Browse the repository at this point in the history
* FIX: include vector handling for command line arguments

* ENH: add flag for number of threads to mdrun

* ENH: expose cell_dim in BaseSimulationBuilder
  • Loading branch information
flongford committed Nov 6, 2020
1 parent 6d26e68 commit 4a0014c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion force_gromacs/commands/base_gromacs_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ def _build_command(self):
for flag, arg in self.command_options.items():
if arg is None:
pass
elif type(arg) == bool:
elif isinstance(arg, bool):
command += ' {}'.format(flag)
else:
if isinstance(arg, list):
arg = ' '.join([str(item) for item in arg])
command += ' {} {}'.format(flag, arg)

return command
Expand Down
2 changes: 1 addition & 1 deletion force_gromacs/commands/gromacs_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Gromacs_mdrun(BaseGromacsCommand):
'-cpo', '-cpi', '-rerun', '-ei',
'-awh', '-mp', '-mn', '-cpnum',
'-nocpnum', '-multidir', '-nsteps',
'-maxh'])
'-maxh', '-nt'])

def _get_name(self):
"""Returns correct name syntax, depending on MPI run
Expand Down
9 changes: 6 additions & 3 deletions force_gromacs/commands/tests/test_base_gromacs_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ class TestBaseGromacsCommand(TestCase):
def setUp(self):
# Create Gromacs command objects
self.gromacs_command = BaseGromacsCommand(
flags=['-c', '-o', '-flag'],
flags=['-c', '-o', '-box', '-flag'],
dry_run=True)

def test___init__(self):
self.assertEqual('gmx', self.gromacs_command.executable)
self.assertListEqual(
['-c', '-o', '-flag'], self.gromacs_command.flags
['-c', '-o', '-box', '-flag'], self.gromacs_command.flags
)
self.assertEqual(
{'-c', '-o', '-flag', '-h'}, self.gromacs_command._flags)
{'-c', '-o', '-box', '-flag', '-h'},
self.gromacs_command._flags)

self.assertTrue(self.gromacs_command.dry_run)
self.assertEqual('', self.gromacs_command.user_input)
Expand Down Expand Up @@ -92,12 +93,14 @@ def test__build_command(self):
self.gromacs_command.command_options = {
'-c': 'coordinate',
'-o': 'output',
'-box': [10, 10, 10],
'-flag': True,
}
command = self.gromacs_command._build_command()
self.assertIn('gmx', command)
self.assertIn(' -c coordinate', command)
self.assertIn(' -o output', command)
self.assertIn(' -box 10 10 10', command)
self.assertIn(' -flag', command)
self.assertNotIn('True', command)

Expand Down
2 changes: 2 additions & 0 deletions force_gromacs/commands/tests/test_gromacs_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ def test_insert_molecules(self):
'-nmol': 30,
'-not_a_flag': 60,
'-o': 'test_output.gro',
'-box': [10, 10, 10],
'-try': True}

self.insert_molecules.command_options = input_options
command = self.insert_molecules.bash_script()
self.assertIn('insert-molecules', command)
self.assertNotIn(' -cp test_coord.gro', command)
self.assertIn(' -o test_output.gro', command)
self.assertIn(' -box 10 10 10', command)
self.assertIn(' -try', command)
self.assertIn(' -nmol 30', command)
self.assertNotIn(' -not_a_flag 60', command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from traits.api import (
HasTraits, Str, Int, Bool, Instance, Directory,
provides
provides, List, Float
)

from force_gromacs.io.gromacs_file_registry import GromacsFileRegistry
Expand Down Expand Up @@ -32,6 +32,9 @@ class BaseGromacsSimulationBuilder(HasTraits):
#: Particle size of simulation
size = Int()

#: Simulation cell dimensions in nm
cell_dim = List(Float, value=[0, 0, 0], maxlen=3, minlen=3)

#: Length of simulation in time steps
n_steps = Int()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test__init__(self):

self.assertEqual('test_experiment', self.sim_builder.name)
self.assertEqual(100, self.sim_builder.size)
self.assertListEqual([0, 0, 0], self.sim_builder.cell_dim)
self.assertEqual(os.path.curdir, self.sim_builder.directory)
self.assertEqual(
os.path.join(os.path.curdir, 'test_experiment'),
Expand Down

0 comments on commit 4a0014c

Please sign in to comment.