From e07210368c3a60a7d15b1b9bb3e88e1dd25a0370 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 20 Aug 2020 08:56:47 -0600 Subject: [PATCH 01/22] added packmol_args parameter to each packing function; appends to PACKMOL_HEADER --- mbuild/packing.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index 1b842b260..bb7be6ff5 100755 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -54,7 +54,7 @@ def fill_box(compound, n_compounds=None, box=None, density=None, overlap=0.2, seed=12345, edge=0.2, compound_ratio=None, aspect_ratio=None, fix_orientation=False, temp_file=None, - update_port_locations=False): + update_port_locations=False, packmol_args=None): """Fill a box with a `mbuild.compound` or `Compound`s using PACKMOL. `fill_box` takes a single `mbuild.Compound` or a @@ -191,6 +191,10 @@ def fill_box(compound, n_compounds=None, box=None, density=None, overlap=0.2, # Apply 1nm edge buffer box_maxs -= edge * 10 + if packmol_args: + for arg in packmol_args: + PACKMOL_HEADER += "{} {} \n".format(arg, packmol_args[arg]) + # Build the input file for each compound and call packmol. filled_xyz = _new_xyz_file() @@ -230,7 +234,7 @@ def fill_box(compound, n_compounds=None, box=None, density=None, overlap=0.2, def fill_region(compound, n_compounds, region, overlap=0.2, seed=12345, edge=0.2, fix_orientation=False, temp_file=None, - update_port_locations=False): + update_port_locations=False, packmol_args=None): """Fill a region of a box with `mbuild.Compound`(s) using PACKMOL. Parameters @@ -296,6 +300,10 @@ def fill_region(compound, n_compounds, region, overlap=0.2, # In angstroms for packmol. overlap *= 10 + if packmol_args: + for arg in packmol_args: + PACKMOL_HEADER += "{} {} \n".format(arg, packmol_args[arg]) + # Build the input file and call packmol. filled_xyz = _new_xyz_file() @@ -337,7 +345,8 @@ def fill_region(compound, n_compounds, region, overlap=0.2, def fill_sphere(compound, sphere, n_compounds=None, density=None, overlap=0.2, seed=12345, edge=0.2, compound_ratio=None, - fix_orientation=False, temp_file=None, update_port_locations=False): + fix_orientation=False, temp_file=None, update_port_locations=False, + packmol_args=None): """Fill a sphere with a compound using packmol. One argument of `n_compounds and density` must be specified. @@ -454,6 +463,10 @@ def fill_sphere(compound, sphere, n_compounds=None, density=None, overlap=0.2, radius *= 10 overlap *= 10 + if packmol_args: + for arg in packmol_args: + PACKMOL_HEADER += "{} {} \n".format(arg, packmol_args[arg]) + # Build the input file for each compound and call packmol. filled_xyz = _new_xyz_file() @@ -490,7 +503,7 @@ def fill_sphere(compound, sphere, n_compounds=None, density=None, overlap=0.2, def solvate(solute, solvent, n_solvent, box, overlap=0.2, seed=12345, edge=0.2, fix_orientation=False, temp_file=None, - update_port_locations=False): + update_port_locations=False, packmol_args=None): """Solvate a compound in a box of solvent using packmol. Parameters @@ -549,6 +562,10 @@ def solvate(solute, solvent, n_solvent, box, overlap=0.2, # Apply edge buffer box_maxs -= edge * 10 + if packmol_args: + for arg in packmol_args: + PACKMOL_HEADER += "{} {} \n".format(arg, packmol_args[arg]) + # Build the input file for each compound and call packmol. solvated_xyz = _new_xyz_file() solute_xyz = _new_xyz_file() From 727d1bf2dc359f2583e7d040047ba07e77c56d46 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 20 Aug 2020 13:17:37 -0600 Subject: [PATCH 02/22] fixed variable error. Create separate variable to store addl packmol commands, and later adds them to PACKMOL_HEADER --- mbuild/packing.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index bb7be6ff5..029a2b368 100755 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -1,4 +1,4 @@ -import os +import os import sys import tempfile import warnings @@ -20,7 +20,7 @@ filetype xyz output {1} seed {2} - +{3} """ PACKMOL_SOLUTE = """ structure {0} @@ -191,9 +191,11 @@ def fill_box(compound, n_compounds=None, box=None, density=None, overlap=0.2, # Apply 1nm edge buffer box_maxs -= edge * 10 + # generate string of addl. packmol inputs given in packmol_args + packmol_commands = "" if packmol_args: for arg in packmol_args: - PACKMOL_HEADER += "{} {} \n".format(arg, packmol_args[arg]) + packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) # Build the input file for each compound and call packmol. filled_xyz = _new_xyz_file() @@ -201,7 +203,7 @@ def fill_box(compound, n_compounds=None, box=None, density=None, overlap=0.2, # create a list to contain the file handles for the compound temp files compound_xyz_list = list() try: - input_text = PACKMOL_HEADER.format(overlap, filled_xyz.name, seed) + input_text = PACKMOL_HEADER.format(overlap, filled_xyz.name, seed, packmol_commands) for comp, m_compounds, rotate in zip(compound, n_compounds, fix_orientation): m_compounds = int(m_compounds) @@ -300,9 +302,11 @@ def fill_region(compound, n_compounds, region, overlap=0.2, # In angstroms for packmol. overlap *= 10 + # generate string of addl. packmol inputs given in packmol_args + packmol_commands = "" if packmol_args: for arg in packmol_args: - PACKMOL_HEADER += "{} {} \n".format(arg, packmol_args[arg]) + packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) # Build the input file and call packmol. filled_xyz = _new_xyz_file() @@ -310,7 +314,7 @@ def fill_region(compound, n_compounds, region, overlap=0.2, # List to hold file handles for the temporary compounds compound_xyz_list = list() try: - input_text = PACKMOL_HEADER.format(overlap, filled_xyz.name, seed) + input_text = PACKMOL_HEADER.format(overlap, filled_xyz.name, seed, packmol_commands) for comp, m_compounds, reg, rotate in zip(compound, n_compounds, region, fix_orientation): m_compounds = int(m_compounds) @@ -463,9 +467,11 @@ def fill_sphere(compound, sphere, n_compounds=None, density=None, overlap=0.2, radius *= 10 overlap *= 10 + # generate string of addl. packmol inputs given in packmol_args + packmol_commands = "" if packmol_args: for arg in packmol_args: - PACKMOL_HEADER += "{} {} \n".format(arg, packmol_args[arg]) + packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) # Build the input file for each compound and call packmol. filled_xyz = _new_xyz_file() @@ -473,7 +479,7 @@ def fill_sphere(compound, sphere, n_compounds=None, density=None, overlap=0.2, # List to hold file handles for the temporary compounds compound_xyz_list = list() try: - input_text = PACKMOL_HEADER.format(overlap, filled_xyz.name, seed) + input_text = PACKMOL_HEADER.format(overlap, filled_xyz.name, seed, packmol_commands) for comp, m_compounds, rotate in zip(compound, n_compounds, fix_orientation): m_compounds = int(m_compounds) @@ -562,9 +568,11 @@ def solvate(solute, solvent, n_solvent, box, overlap=0.2, # Apply edge buffer box_maxs -= edge * 10 + # generate string of addl. packmol inputs given in packmol_args + packmol_commands = "" if packmol_args: for arg in packmol_args: - PACKMOL_HEADER += "{} {} \n".format(arg, packmol_args[arg]) + packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) # Build the input file for each compound and call packmol. solvated_xyz = _new_xyz_file() @@ -574,7 +582,7 @@ def solvate(solute, solvent, n_solvent, box, overlap=0.2, solvent_xyz_list = list() try: solute.save(solute_xyz.name, overwrite=True) - input_text = (PACKMOL_HEADER.format(overlap, solvated_xyz.name, seed) + + input_text = (PACKMOL_HEADER.format(overlap, solvated_xyz.name, seed, packmol_commands) + PACKMOL_SOLUTE.format(solute_xyz.name, *center_solute)) for solv, m_solvent, rotate in zip(solvent, n_solvent, fix_orientation): From a81f9f44ef5fe2fdf3ed0b682721d7217be6f481 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 23 Aug 2020 20:55:21 -0600 Subject: [PATCH 03/22] added doc strings, unit test for packmol_args --- mbuild/packing.py | 44 ++++++++++++++++++++++++++++++++++++ mbuild/tests/test_packing.py | 14 ++++++++++++ 2 files changed, 58 insertions(+) diff --git a/mbuild/packing.py b/mbuild/packing.py index 029a2b368..ece25ff9a 100755 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -112,6 +112,17 @@ def fill_box(compound, n_compounds=None, box=None, density=None, overlap=0.2, update_port_locations : bool, default=False After packing, port locations can be updated, but since compounds can be rotated, port orientation may be incorrect. + packmol_args : dict + Dictionary where the key, value pairs are options and their + corresponding keyword arguments for PACKMOL. Some PACKMOL options + do not require a specified keyword. In this case, the value in + the dictionary should be an empty string e.g. {'movebadrandom':""} + These commands are placed at the header of the PACKMOL input file + and therefore applied to all structures. NOTE: The PACKMOL options + for seed and tolerance are specified by the function parameters + seed and overlap. + Other command options can be found in the PACKMOL userguide: + http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml Returns ------- @@ -263,6 +274,17 @@ def fill_region(compound, n_compounds, region, overlap=0.2, update_port_locations : bool, default=False After packing, port locations can be updated, but since compounds can be rotated, port orientation may be incorrect. + packmol_args : dict + Dictionary where the key, value pairs are options and their + corresponding keyword arguments for PACKMOL. Some PACKMOL options + do not require a specified keyword. In this case, the value in + the dictionary should be an empty string e.g. {'movebadrandom':""} + These commands are placed at the header of the PACKMOL input file + and therefore applied to all structures. NOTE: The PACKMOL options + for seed and tolerance are specified by the function parameters + seed and overlap. + Other command options can be found in the PACKMOL userguide: + http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml Returns ------- @@ -391,6 +413,17 @@ def fill_sphere(compound, sphere, n_compounds=None, density=None, overlap=0.2, update_port_locations : bool, default=False After packing, port locations can be updated, but since compounds can be rotated, port orientation may be incorrect. + packmol_args : dict + Dictionary where the key, value pairs are options and their + corresponding keyword arguments for PACKMOL. Some PACKMOL options + do not require a specified keyword. In this case, the value in + the dictionary should be an empty string e.g. {'movebadrandom':""} + These commands are placed at the header of the PACKMOL input file + and therefore applied to all structures. NOTE: The PACKMOL options + for seed and tolerance are specified by the function parameters + seed and overlap. + Other command options can be found in the PACKMOL userguide: + http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml Returns ------- @@ -538,6 +571,17 @@ def solvate(solute, solvent, n_solvent, box, overlap=0.2, update_port_locations : bool, default=False After packing, port locations can be updated, but since compounds can be rotated, port orientation may be incorrect. + packmol_args : dict + Dictionary where the key, value pairs are options and their + corresponding keyword arguments for PACKMOL. Some PACKMOL options + do not require a specified keyword. In this case, the value in + the dictionary should be an empty string e.g. {'movebadrandom':""} + These commands are placed at the header of the PACKMOL input file + and therefore applied to all structures. NOTE: The PACKMOL options + for seed and tolerance are specified by the function parameters + seed and overlap. + Other command options can be found in the PACKMOL userguide: + http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml Returns ------- diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index 944872f5f..7168bc44f 100755 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -199,6 +199,20 @@ def test_packmol_warning(self, h2o): with pytest.warns(UserWarning): filled = mb.fill_box(h2o, n_compounds=10, box=[1, 1, 1], overlap=10) + def test_packmol_args(self, h2o): + try: + filled = mb.fill_box(h2o, n_compounds=2, box=[.1, .1, .1], + packmol_args={"maxit": 10, + "movebadrandom":"", + "nloop": 100}) + except(RuntimeError): + with open('log.txt', 'r') as logfile: + assert "The maximum number of cycles ( 100 ) was achieved" in logfile.read() + logfile.seek(0) + assert "(movebadrandom)" in logfile.read() + logfile.seek(0) + assert "User defined GENCAN number of iterations: 10" in logfile.read() + def test_rotate(self, h2o): filled = mb.fill_box(h2o, 2, box=[1, 1, 1], fix_orientation=True) w0 = filled.xyz[:3] From deb43430e142f3c09448eb0399084ca8528a9264 Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Thu, 15 Oct 2020 14:40:37 -0600 Subject: [PATCH 04/22] added defaults dict, beginning of function to parse through --- mbuild/packing.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index ece25ff9a..02660d812 100755 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -15,6 +15,7 @@ __all__ = ['fill_box', 'fill_region', 'fill_sphere', 'solvate'] PACKMOL = find_executable('packmol') + PACKMOL_HEADER = """ tolerance {0:.16f} filetype xyz @@ -43,13 +44,24 @@ {6} end structure """ - PACKMOL_CONSTRAIN = """ constrain_rotation x 0. 0. constrain_rotation y 0. 0. constrain_rotation z 0. 0. """ +packmol_default_args = {'tolerance': 0.2, 'seed': 12345} + +def combine_packmol_args(default_args, custom_args): + + # List of all available packmol_inputs + packmol_inputs = [] + + # + + #Parse through custom args first + + #Combine into single dict def fill_box(compound, n_compounds=None, box=None, density=None, overlap=0.2, seed=12345, edge=0.2, compound_ratio=None, From b4f674e81714fa3ec86e3591c1dcb20cb0ec32d0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 16:32:10 +0000 Subject: [PATCH 05/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mbuild/packing.py | 40 +++++++++++++++++++----------------- mbuild/tests/test_packing.py | 24 ++++++++++++++-------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index dccfe735d..bb37e5cc2 100644 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -20,7 +20,7 @@ __all__ = ["fill_box", "fill_region", "fill_sphere", "solvate"] -PACKMOL = find_executable('packmol') +PACKMOL = find_executable("packmol") PACKMOL_HEADER = """ tolerance {0:.16f} filetype xyz @@ -60,18 +60,20 @@ constrain_rotation z 0. 0. """ -packmol_default_args = {'tolerance': 0.2, 'seed': 12345} +packmol_default_args = {"tolerance": 0.2, "seed": 12345} + def combine_packmol_args(default_args, custom_args): - + # List of all available packmol_inputs - packmol_inputs = [] - + packmol_inputs = [] + # - #Parse through custom args first - - #Combine into single dict + # Parse through custom args first + + # Combine into single dict + def fill_box( compound, @@ -87,7 +89,7 @@ def fill_box( fix_orientation=False, temp_file=None, update_port_locations=False, - packmol_args=None + packmol_args=None, ): """Fill a box with an `mbuild.compound` or `Compound` s using PACKMOL. @@ -158,7 +160,7 @@ def fill_box( and therefore applied to all structures. NOTE: The PACKMOL options for seed and tolerance are specified by the function parameters seed and overlap. - Other command options can be found in the PACKMOL userguide: + Other command options can be found in the PACKMOL userguide: http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml Returns @@ -264,7 +266,7 @@ def fill_box( if packmol_args: for arg in packmol_args: packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) - + # Build the input file for each compound and call packmol. filled_xyz = _new_xyz_file() @@ -325,7 +327,7 @@ def fill_region( fix_orientation=False, temp_file=None, update_port_locations=False, - packmol_args=None + packmol_args=None, ): """Fill a region of a box with `mbuild.Compound` (s) using PACKMOL. @@ -373,7 +375,7 @@ def fill_region( and therefore applied to all structures. NOTE: The PACKMOL options for seed and tolerance are specified by the function parameters seed and overlap. - Other command options can be found in the PACKMOL userguide: + Other command options can be found in the PACKMOL userguide: http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml Returns @@ -458,7 +460,7 @@ def fill_region( if packmol_args: for arg in packmol_args: packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) - + # Build the input file and call packmol. filled_xyz = _new_xyz_file() @@ -527,7 +529,7 @@ def fill_sphere( fix_orientation=False, temp_file=None, update_port_locations=False, - packmol_args=None + packmol_args=None, ): """Fill a sphere with a compound using PACKMOL. @@ -582,7 +584,7 @@ def fill_sphere( and therefore applied to all structures. NOTE: The PACKMOL options for seed and tolerance are specified by the function parameters seed and overlap. - Other command options can be found in the PACKMOL userguide: + Other command options can be found in the PACKMOL userguide: http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml Returns @@ -740,7 +742,7 @@ def solvate( temp_file=None, update_port_locations=False, center_solute=True, - packmol_args=None + packmol_args=None, ): """Solvate a compound in a box of solvent using PACKMOL. @@ -782,10 +784,10 @@ def solvate( do not require a specified keyword. In this case, the value in the dictionary should be an empty string e.g. {'movebadrandom':""} These commands are placed at the header of the PACKMOL input file - and therefore applied to all structures. NOTE: The PACKMOL options + and therefore applied to all structures. NOTE: The PACKMOL options for seed and tolerance are specified by the function parameters seed and overlap. - Other command options can be found in the PACKMOL userguide: + Other command options can be found in the PACKMOL userguide: http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml Returns diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index a11d921e6..f2319ec37 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -307,17 +307,25 @@ def test_packmol_warning(self, h2o): def test_packmol_args(self, h2o): try: - filled = mb.fill_box(h2o, n_compounds=2, box=[.1, .1, .1], - packmol_args={"maxit": 10, - "movebadrandom":"", - "nloop": 100}) - except(RuntimeError): - with open('log.txt', 'r') as logfile: - assert "The maximum number of cycles ( 100 ) was achieved" in logfile.read() + filled = mb.fill_box( + h2o, + n_compounds=2, + box=[0.1, 0.1, 0.1], + packmol_args={"maxit": 10, "movebadrandom": "", "nloop": 100}, + ) + except RuntimeError: + with open("log.txt", "r") as logfile: + assert ( + "The maximum number of cycles ( 100 ) was achieved" + in logfile.read() + ) logfile.seek(0) assert "(movebadrandom)" in logfile.read() logfile.seek(0) - assert "User defined GENCAN number of iterations: 10" in logfile.read() + assert ( + "User defined GENCAN number of iterations: 10" + in logfile.read() + ) def test_rotate(self, h2o): filled = mb.fill_box(h2o, 2, box=[1, 1, 1], fix_orientation=True) From e67b3fcb65ebc54999f4ab3f24727f649f32aa29 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 7 May 2024 12:39:02 -0600 Subject: [PATCH 06/22] fix variable name typo --- mbuild/packing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index bb37e5cc2..0b9a0416b 100644 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -692,7 +692,7 @@ def fill_sphere( compound_xyz_list = list() try: input_text = PACKMOL_HEADER.format( - overlap, filled_xyz.name, seed, sidemax * 10, packmold_commands + overlap, filled_xyz.name, seed, sidemax * 10, packmol_commands ) for comp, m_compounds, rotate in zip( compound, n_compounds, fix_orientation From add1f857f5807a97f55eed05525884442ec44dbb Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 7 May 2024 14:45:54 -0600 Subject: [PATCH 07/22] fix unit test --- mbuild/tests/test_packing.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index f2319ec37..cd30fc1eb 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -315,11 +315,6 @@ def test_packmol_args(self, h2o): ) except RuntimeError: with open("log.txt", "r") as logfile: - assert ( - "The maximum number of cycles ( 100 ) was achieved" - in logfile.read() - ) - logfile.seek(0) assert "(movebadrandom)" in logfile.read() logfile.seek(0) assert ( From 5db9a301332186529e2b543da2ae62fa280ef296 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 7 May 2024 15:00:12 -0600 Subject: [PATCH 08/22] test all packing methods with packmol args --- mbuild/tests/test_packing.py | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index cd30fc1eb..aed5828b9 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -322,6 +322,55 @@ def test_packmol_args(self, h2o): in logfile.read() ) + try: + mb.fill_region( + h2o, + 10, + [[2, 2, 2, 4, 4, 4]], + bounds=[[2, 2, 2, 4, 4, 4]], + packmol_args={"maxit": 10, "movebadrandom": "", "nloop": 100}, + ) + except RuntimeError: + with open("log.txt", "r") as logfile: + assert "(movebadrandom)" in logfile.read() + logfile.seek(0) + assert ( + "User defined GENCAN number of iterations: 10" + in logfile.read() + ) + + try: + filled = mb.fill_sphere( + h2o, + n_compounds=2, + sphere=[3, 3, 3, 1.5], + packmol_args={"maxit": 10, "movebadrandom": "", "nloop": 100}, + ) + except RuntimeError: + with open("log.txt", "r") as logfile: + assert "(movebadrandom)" in logfile.read() + logfile.seek(0) + assert ( + "User defined GENCAN number of iterations: 10" + in logfile.read() + ) + try: + mb.solvate( + solute=h2o, + solvent=[h2o], + n_solvent=[10], + box=[2, 2, 2], + packmol_args={"maxit": 15, "movebadrandom": "", "nloop": 100}, + ) + except RuntimeError: + with open("log.txt", "r") as logfile: + assert "(movebadrandom)" in logfile.read() + logfile.seek(0) + assert ( + "User defined GENCAN number of iterations: 15" + in logfile.read() + ) + def test_rotate(self, h2o): filled = mb.fill_box(h2o, 2, box=[1, 1, 1], fix_orientation=True) w0 = filled.xyz[:3] From 04215cbb342e6763c0b4bc6da42e95b75725245c Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 7 May 2024 15:14:52 -0600 Subject: [PATCH 09/22] remove unused variables in tests --- mbuild/tests/test_packing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index aed5828b9..b3be5e88e 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -307,7 +307,7 @@ def test_packmol_warning(self, h2o): def test_packmol_args(self, h2o): try: - filled = mb.fill_box( + mb.fill_box( h2o, n_compounds=2, box=[0.1, 0.1, 0.1], @@ -340,7 +340,7 @@ def test_packmol_args(self, h2o): ) try: - filled = mb.fill_sphere( + mb.fill_sphere( h2o, n_compounds=2, sphere=[3, 3, 3, 1.5], From 6170db3573edc3cf173b78189f7058f9b65bc827 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 7 May 2024 18:46:40 -0600 Subject: [PATCH 10/22] add method to check args, add unit tests --- mbuild/packing.py | 48 +++++++++++++++++++++++++++--------- mbuild/tests/test_packing.py | 33 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index 0b9a0416b..9e4b593d2 100644 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -60,19 +60,39 @@ constrain_rotation z 0. 0. """ -packmol_default_args = {"tolerance": 0.2, "seed": 12345} - -def combine_packmol_args(default_args, custom_args): - - # List of all available packmol_inputs - packmol_inputs = [] - - # - - # Parse through custom args first - - # Combine into single dict +def check_packmol_args(custom_args): + # List of all available packmol_inputs. + # Only file-level arguments can be passed. + allowed_args = [ + "maxit", # int + "nloop", # int + "fbins", # float + "discale", # float + "movefrac", # float + "avoid_overlap", # On/Off (empty string "" is on) + "precision", # float + "movebadrandom", # On/off (empty string "" is on) + "use_short_tol", # On/off (empty string "" is on) + "short_tol_dist", # float + "short_tol_scale", # float + ] + default_args = ["tolerance", "seed", "sidemax"] + for key in custom_args: + if key not in allowed_args: + raise ValueError( + f"PACKMOL argument {key} is not usable in `packmol_args`. " + f"Availble arguments that can be set are {allowed_args}." + "Only file-level arguments can be set with `packmol_args`." + "See https://m3g.github.io/packmol/userguide.shtml#run" + ) + if key in default_args: + warnings.warn( + f"The PACKMOL argument {key} was passed to `packmol_args`, " + "but should be set using the corresponding function parameters. " + "The value passed to the function will be used. " + "See the function's parameters for more information." + ) def fill_box( @@ -262,6 +282,7 @@ def fill_box( box_mins = [a_min + (edge * 10) for a_min in box_mins] # generate string of addl. packmol inputs given in packmol_args + check_packmol_args(packmol_args) packmol_commands = "" if packmol_args: for arg in packmol_args: @@ -456,6 +477,7 @@ def fill_region( overlap *= 10 # generate string of addl. packmol inputs given in packmol_args + check_packmol_args(packmol_args) packmol_commands = "" if packmol_args: for arg in packmol_args: @@ -680,6 +702,7 @@ def fill_sphere( overlap *= 10 # generate string of addl. packmol inputs given in packmol_args + check_packmol_args(packmol_args) packmol_commands = "" if packmol_args: for arg in packmol_args: @@ -821,6 +844,7 @@ def solvate( box_mins = np.add(box_mins, edge * 10) # generate string of addl. packmol inputs given in packmol_args + check_packmol_args(packmol_args) packmol_commands = "" if packmol_args: for arg in packmol_args: diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index b3be5e88e..8eafe3cce 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -371,6 +371,39 @@ def test_packmol_args(self, h2o): in logfile.read() ) + def test_packmol_args_bad(self, h2o): + with pytest.raises(ValueError): + mb.fill_box( + h2o, + n_compounds=2, + box=[10, 10, 10], + packmol_args={"bad_arg": 10}, + ) + + @pytest.mark.parametrize( + "args", + [ + dict(maxit=500), + dict(nloop=1000), + dict(movebadrandom=""), + dict(fbins=1.2), + dict(discale=1.5), + dict(movefrac=0.05), + dict(avoid_overlap=""), + dict(precision=0.02), + dict(use_short_tol="", short_tol_dist=0.5), + dict(use_short_tol="", short_tol_scale=1.2) + ] + ) + def test_packmol_args_allowed(self, args): + mb.fill_box( + mb.load("C", smiles=True), + n_compounds=10, + box=[10, 10, 10], + packmol_args=args, + ) + + def test_rotate(self, h2o): filled = mb.fill_box(h2o, 2, box=[1, 1, 1], fix_orientation=True) w0 = filled.xyz[:3] From 880e6265ed03bdcfd8be585e5791a6f8812872a0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 8 May 2024 00:46:57 +0000 Subject: [PATCH 11/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mbuild/packing.py | 38 +++++++++++++++++------------------ mbuild/tests/test_packing.py | 39 ++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index 9e4b593d2..2afd04cfb 100644 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -65,33 +65,33 @@ def check_packmol_args(custom_args): # List of all available packmol_inputs. # Only file-level arguments can be passed. allowed_args = [ - "maxit", # int - "nloop", # int - "fbins", # float - "discale", # float - "movefrac", # float - "avoid_overlap", # On/Off (empty string "" is on) - "precision", # float - "movebadrandom", # On/off (empty string "" is on) - "use_short_tol", # On/off (empty string "" is on) - "short_tol_dist", # float - "short_tol_scale", # float + "maxit", # int + "nloop", # int + "fbins", # float + "discale", # float + "movefrac", # float + "avoid_overlap", # On/Off (empty string "" is on) + "precision", # float + "movebadrandom", # On/off (empty string "" is on) + "use_short_tol", # On/off (empty string "" is on) + "short_tol_dist", # float + "short_tol_scale", # float ] default_args = ["tolerance", "seed", "sidemax"] for key in custom_args: if key not in allowed_args: raise ValueError( - f"PACKMOL argument {key} is not usable in `packmol_args`. " - f"Availble arguments that can be set are {allowed_args}." - "Only file-level arguments can be set with `packmol_args`." - "See https://m3g.github.io/packmol/userguide.shtml#run" + f"PACKMOL argument {key} is not usable in `packmol_args`. " + f"Availble arguments that can be set are {allowed_args}." + "Only file-level arguments can be set with `packmol_args`." + "See https://m3g.github.io/packmol/userguide.shtml#run" ) if key in default_args: warnings.warn( - f"The PACKMOL argument {key} was passed to `packmol_args`, " - "but should be set using the corresponding function parameters. " - "The value passed to the function will be used. " - "See the function's parameters for more information." + f"The PACKMOL argument {key} was passed to `packmol_args`, " + "but should be set using the corresponding function parameters. " + "The value passed to the function will be used. " + "See the function's parameters for more information." ) diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index 8eafe3cce..7c2de244f 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -381,28 +381,27 @@ def test_packmol_args_bad(self, h2o): ) @pytest.mark.parametrize( - "args", - [ - dict(maxit=500), - dict(nloop=1000), - dict(movebadrandom=""), - dict(fbins=1.2), - dict(discale=1.5), - dict(movefrac=0.05), - dict(avoid_overlap=""), - dict(precision=0.02), - dict(use_short_tol="", short_tol_dist=0.5), - dict(use_short_tol="", short_tol_scale=1.2) - ] + "args", + [ + dict(maxit=500), + dict(nloop=1000), + dict(movebadrandom=""), + dict(fbins=1.2), + dict(discale=1.5), + dict(movefrac=0.05), + dict(avoid_overlap=""), + dict(precision=0.02), + dict(use_short_tol="", short_tol_dist=0.5), + dict(use_short_tol="", short_tol_scale=1.2), + ], ) def test_packmol_args_allowed(self, args): - mb.fill_box( - mb.load("C", smiles=True), - n_compounds=10, - box=[10, 10, 10], - packmol_args=args, - ) - + mb.fill_box( + mb.load("C", smiles=True), + n_compounds=10, + box=[10, 10, 10], + packmol_args=args, + ) def test_rotate(self, h2o): filled = mb.fill_box(h2o, 2, box=[1, 1, 1], fix_orientation=True) From 4b27d2bc7be8e2db90856157fcb0a866c70ea643 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 7 May 2024 18:50:48 -0600 Subject: [PATCH 12/22] add test for warnings --- mbuild/packing.py | 17 ++++++++++------- mbuild/tests/test_packing.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index 9e4b593d2..7944bcdf6 100644 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -76,16 +76,12 @@ def check_packmol_args(custom_args): "use_short_tol", # On/off (empty string "" is on) "short_tol_dist", # float "short_tol_scale", # float + "tolerance", + "seed", + "sidemax", ] default_args = ["tolerance", "seed", "sidemax"] for key in custom_args: - if key not in allowed_args: - raise ValueError( - f"PACKMOL argument {key} is not usable in `packmol_args`. " - f"Availble arguments that can be set are {allowed_args}." - "Only file-level arguments can be set with `packmol_args`." - "See https://m3g.github.io/packmol/userguide.shtml#run" - ) if key in default_args: warnings.warn( f"The PACKMOL argument {key} was passed to `packmol_args`, " @@ -93,6 +89,13 @@ def check_packmol_args(custom_args): "The value passed to the function will be used. " "See the function's parameters for more information." ) + if key not in allowed_args: + raise ValueError( + f"PACKMOL argument {key} is not usable in `packmol_args`. " + f"Availble arguments that can be set are {allowed_args}." + "Only file-level arguments can be set with `packmol_args`." + "See https://m3g.github.io/packmol/userguide.shtml#run" + ) def fill_box( diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index 8eafe3cce..fb414e4f4 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -403,6 +403,23 @@ def test_packmol_args_allowed(self, args): packmol_args=args, ) + @pytest.mark.parametrize( + "args", + [ + dict(tolerance=0.2), + dict(seed=42), + dict(sidemax=2.0), + ] + ) + def test_packmol_args_default(self, args): + with pytest.warns(): + mb.fill_box( + mb.load("C", smiles=True), + n_compounds=10, + box=[10, 10, 10], + packmol_args=args, + ) + def test_rotate(self, h2o): filled = mb.fill_box(h2o, 2, box=[1, 1, 1], fix_orientation=True) From 0ef57ec56024ac3a359c23c3511af85153fa9174 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 7 May 2024 18:54:04 -0600 Subject: [PATCH 13/22] remove remaining conflict message --- mbuild/packing.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index 1f2569675..63782b22b 100644 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -65,30 +65,29 @@ def check_packmol_args(custom_args): # List of all available packmol_inputs. # Only file-level arguments can be passed. allowed_args = [ -<<<<<<< HEAD - "maxit", # int - "nloop", # int - "fbins", # float - "discale", # float - "movefrac", # float - "avoid_overlap", # On/Off (empty string "" is on) - "precision", # float - "movebadrandom", # On/off (empty string "" is on) - "use_short_tol", # On/off (empty string "" is on) - "short_tol_dist", # float - "short_tol_scale", # float - "tolerance", - "seed", - "sidemax", + "maxit", # int + "nloop", # int + "fbins", # float + "discale", # float + "movefrac", # float + "avoid_overlap", # On/Off (empty string "" is on) + "precision", # float + "movebadrandom", # On/off (empty string "" is on) + "use_short_tol", # On/off (empty string "" is on) + "short_tol_dist", # float + "short_tol_scale", # float + "tolerance", + "seed", + "sidemax", ] default_args = ["tolerance", "seed", "sidemax"] for key in custom_args: if key not in allowed_args: raise ValueError( - f"PACKMOL argument {key} is not usable in `packmol_args`. " - f"Availble arguments that can be set are {allowed_args}." - "Only file-level arguments can be set with `packmol_args`." - "See https://m3g.github.io/packmol/userguide.shtml#run" + f"PACKMOL argument {key} is not usable in `packmol_args`. " + f"Availble arguments that can be set are {allowed_args}." + "Only file-level arguments can be set with `packmol_args`." + "See https://m3g.github.io/packmol/userguide.shtml#run" ) if key in default_args: warnings.warn( From 4c189140efc8c721912c952573a76c35149a1fdb Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 7 May 2024 19:04:02 -0600 Subject: [PATCH 14/22] fix conflicts, move check args func under if statement --- mbuild/packing.py | 8 +++---- mbuild/tests/test_packing.py | 42 +++++++++++------------------------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index 63782b22b..86fd4750b 100644 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -285,9 +285,9 @@ def fill_box( box_mins = [a_min + (edge * 10) for a_min in box_mins] # generate string of addl. packmol inputs given in packmol_args - check_packmol_args(packmol_args) packmol_commands = "" if packmol_args: + check_packmol_args(packmol_args) for arg in packmol_args: packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) @@ -480,9 +480,9 @@ def fill_region( overlap *= 10 # generate string of addl. packmol inputs given in packmol_args - check_packmol_args(packmol_args) packmol_commands = "" if packmol_args: + check_packmol_args(packmol_args) for arg in packmol_args: packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) @@ -705,9 +705,9 @@ def fill_sphere( overlap *= 10 # generate string of addl. packmol inputs given in packmol_args - check_packmol_args(packmol_args) packmol_commands = "" if packmol_args: + check_packmol_args(packmol_args) for arg in packmol_args: packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) @@ -847,9 +847,9 @@ def solvate( box_mins = np.add(box_mins, edge * 10) # generate string of addl. packmol inputs given in packmol_args - check_packmol_args(packmol_args) packmol_commands = "" if packmol_args: + check_packmol_args(packmol_args) for arg in packmol_args: packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index 2ce7036e2..e78484c67 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -396,21 +396,20 @@ def test_packmol_args_bad(self, h2o): ], ) def test_packmol_args_allowed(self, args): -<<<<<<< HEAD - mb.fill_box( - mb.load("C", smiles=True), - n_compounds=10, - box=[10, 10, 10], - packmol_args=args, - ) + mb.fill_box( + mb.load("C", smiles=True), + n_compounds=10, + box=[10, 10, 10], + packmol_args=args, + ) @pytest.mark.parametrize( - "args", - [ - dict(tolerance=0.2), - dict(seed=42), - dict(sidemax=2.0), - ] + "args", + [ + dict(tolerance=0.2), + dict(seed=42), + dict(sidemax=2.0), + ], ) def test_packmol_args_default(self, args): with pytest.warns(): @@ -421,23 +420,6 @@ def test_packmol_args_default(self, args): packmol_args=args, ) -||||||| 6170db35 - mb.fill_box( - mb.load("C", smiles=True), - n_compounds=10, - box=[10, 10, 10], - packmol_args=args, - ) - -======= - mb.fill_box( - mb.load("C", smiles=True), - n_compounds=10, - box=[10, 10, 10], - packmol_args=args, - ) ->>>>>>> 880e6265ed03bdcfd8be585e5791a6f8812872a0 - def test_rotate(self, h2o): filled = mb.fill_box(h2o, 2, box=[1, 1, 1], fix_orientation=True) w0 = filled.xyz[:3] From e91d14d3fca4f8b349346f55c37933627485018c Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Tue, 7 May 2024 19:17:20 -0600 Subject: [PATCH 15/22] clean up arg dict parsing --- mbuild/packing.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index 86fd4750b..d639f52e1 100644 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -288,8 +288,8 @@ def fill_box( packmol_commands = "" if packmol_args: check_packmol_args(packmol_args) - for arg in packmol_args: - packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) + for arg, val in packmol_args.items(): + packmol_commands += f"{arg} {val} \n" # Build the input file for each compound and call packmol. filled_xyz = _new_xyz_file() @@ -483,8 +483,8 @@ def fill_region( packmol_commands = "" if packmol_args: check_packmol_args(packmol_args) - for arg in packmol_args: - packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) + for arg, val in packmol_args.items(): + packmol_commands += f"{arg} {val} \n" # Build the input file and call packmol. filled_xyz = _new_xyz_file() @@ -708,8 +708,8 @@ def fill_sphere( packmol_commands = "" if packmol_args: check_packmol_args(packmol_args) - for arg in packmol_args: - packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) + for arg, val in packmol_args.items(): + packmol_commands += f"{arg} {val} \n" # Build the input file for each compound and call packmol. filled_xyz = _new_xyz_file() @@ -850,8 +850,8 @@ def solvate( packmol_commands = "" if packmol_args: check_packmol_args(packmol_args) - for arg in packmol_args: - packmol_commands += "{} {} \n".format(arg, packmol_args[arg]) + for arg, val in packmol_args.items(): + packmol_commands += f"{arg} {val} \n" # Build the input file for each compound and call packmol. solvated_xyz = _new_xyz_file() From bca14980cac9630c31dc07808147d7e044ad6c21 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Wed, 8 May 2024 08:42:39 -0600 Subject: [PATCH 16/22] remove use_short_tol from test so Windows can pass --- mbuild/tests/test_packing.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index e78484c67..718053e0c 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -391,8 +391,6 @@ def test_packmol_args_bad(self, h2o): dict(movefrac=0.05), dict(avoid_overlap=""), dict(precision=0.02), - dict(use_short_tol="", short_tol_dist=0.5), - dict(use_short_tol="", short_tol_scale=1.2), ], ) def test_packmol_args_allowed(self, args): From 5309c2b6811242e6ecac9894882fc54eca1d0fa6 Mon Sep 17 00:00:00 2001 From: chrisjonesbsu Date: Mon, 20 May 2024 16:04:40 -0600 Subject: [PATCH 17/22] fix error handling in tests --- mbuild/tests/test_packing.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index 718053e0c..02529fb94 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -306,14 +306,13 @@ def test_packmol_warning(self, h2o): mb.fill_box(h2o, n_compounds=10, box=[1, 1, 1], overlap=10) def test_packmol_args(self, h2o): - try: + with pytest.raises(RuntimeError): mb.fill_box( h2o, - n_compounds=2, + n_compounds=10, box=[0.1, 0.1, 0.1], packmol_args={"maxit": 10, "movebadrandom": "", "nloop": 100}, ) - except RuntimeError: with open("log.txt", "r") as logfile: assert "(movebadrandom)" in logfile.read() logfile.seek(0) @@ -322,15 +321,14 @@ def test_packmol_args(self, h2o): in logfile.read() ) - try: + with pytest.raises(RuntimeError): mb.fill_region( h2o, 10, - [[2, 2, 2, 4, 4, 4]], - bounds=[[2, 2, 2, 4, 4, 4]], + [[0.2, 0.2, 0.2, 0.4, 0.4, 0.4]], + bounds=[[0.2, 0.2, 0.2, 0.4, 0.4, 0.4]], packmol_args={"maxit": 10, "movebadrandom": "", "nloop": 100}, ) - except RuntimeError: with open("log.txt", "r") as logfile: assert "(movebadrandom)" in logfile.read() logfile.seek(0) @@ -339,30 +337,28 @@ def test_packmol_args(self, h2o): in logfile.read() ) - try: + with pytest.raises(RuntimeError): mb.fill_sphere( h2o, - n_compounds=2, - sphere=[3, 3, 3, 1.5], - packmol_args={"maxit": 10, "movebadrandom": "", "nloop": 100}, + n_compounds=10, + sphere=[1, 1, 1, 0.5], + packmol_args={"maxit": 1, "movebadrandom": "", "nloop": 1}, ) - except RuntimeError: with open("log.txt", "r") as logfile: assert "(movebadrandom)" in logfile.read() logfile.seek(0) assert ( - "User defined GENCAN number of iterations: 10" + "User defined GENCAN number of iterations: 1" in logfile.read() ) - try: + with pytest.raises(RuntimeError): mb.solvate( solute=h2o, solvent=[h2o], n_solvent=[10], - box=[2, 2, 2], + box=[0.2, 0.2, 0.2], packmol_args={"maxit": 15, "movebadrandom": "", "nloop": 100}, ) - except RuntimeError: with open("log.txt", "r") as logfile: assert "(movebadrandom)" in logfile.read() logfile.seek(0) From a112de5799b9afe39ac39513aabf9ba8d6f3d2bc Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Thu, 23 May 2024 13:37:56 -0600 Subject: [PATCH 18/22] update doc strings --- mbuild/packing.py | 110 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/mbuild/packing.py b/mbuild/packing.py index d639f52e1..058ae6f01 100644 --- a/mbuild/packing.py +++ b/mbuild/packing.py @@ -94,7 +94,7 @@ def check_packmol_args(custom_args): f"The PACKMOL argument {key} was passed to `packmol_args`, " "but should be set using the corresponding function parameters. " "The value passed to the function will be used. " - "See the function's parameters for more information." + "See the function's doc strings for more information." ) @@ -186,6 +186,33 @@ def fill_box( Other command options can be found in the PACKMOL userguide: http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml + Notes + ----- + The packmol_args parameter is designed to only accept file-level + PACKMOL arguments, as opposed to molecule level arguments. + + The allowed arguments include the following: + + "maxit", # int + "nloop", # int + "fbins", # float + "discale", # float + "movefrac", # float + "avoid_overlap", # On/Off (empty string "" is on) + "precision", # float + "movebadrandom", # On/off (empty string "" is on) + "use_short_tol", # On/off (empty string "" is on) + "short_tol_dist", # float + "short_tol_scale", # float + + The following PACKMOL arguments should be specified + by the mbuild.packing method's parameters: + + "tolerance", "seed", "sidemax" + + See the PACKMOL documentation for detailed explanations of these arguments: + http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml + Returns ------- filled : mb.Compound @@ -402,6 +429,33 @@ def fill_region( Other command options can be found in the PACKMOL userguide: http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml + Notes + ----- + The packmol_args parameter is designed to only accept file-level + PACKMOL arguments, as opposed to molecule level arguments. + + The allowed arguments include the following: + + "maxit", # int + "nloop", # int + "fbins", # float + "discale", # float + "movefrac", # float + "avoid_overlap", # On/Off (empty string "" is on) + "precision", # float + "movebadrandom", # On/off (empty string "" is on) + "use_short_tol", # On/off (empty string "" is on) + "short_tol_dist", # float + "short_tol_scale", # float + + The following PACKMOL arguments should be specified + by the mbuild.packing method's parameters: + + "tolerance", "seed", "sidemax" + + See the PACKMOL documentation for detailed explanations of these arguments: + http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml + Returns ------- filled : mb.Compound @@ -612,6 +666,33 @@ def fill_sphere( Other command options can be found in the PACKMOL userguide: http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml + Notes + ----- + The packmol_args parameter is designed to only accept file-level + PACKMOL arguments, as opposed to molecule level arguments. + + The allowed arguments include the following: + + "maxit", # int + "nloop", # int + "fbins", # float + "discale", # float + "movefrac", # float + "avoid_overlap", # On/Off (empty string "" is on) + "precision", # float + "movebadrandom", # On/off (empty string "" is on) + "use_short_tol", # On/off (empty string "" is on) + "short_tol_dist", # float + "short_tol_scale", # float + + The following PACKMOL arguments should be specified + by the mbuild.packing method's parameters: + + "tolerance", "seed", "sidemax" + + See the PACKMOL documentation for detailed explanations of these arguments: + http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml + Returns ------- filled : mb.Compound @@ -816,6 +897,33 @@ def solvate( Other command options can be found in the PACKMOL userguide: http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml + Notes + ----- + The packmol_args parameter is designed to only accept file-level + PACKMOL arguments, as opposed to molecule level arguments. + + The allowed arguments include the following: + + "maxit", # int + "nloop", # int + "fbins", # float + "discale", # float + "movefrac", # float + "avoid_overlap", # On/Off (empty string "" is on) + "precision", # float + "movebadrandom", # On/off (empty string "" is on) + "use_short_tol", # On/off (empty string "" is on) + "short_tol_dist", # float + "short_tol_scale", # float + + The following PACKMOL arguments should be specified + by the mbuild.packing method's parameters: + + "tolerance", "seed", "sidemax" + + See the PACKMOL documentation for detailed explanations of these arguments: + http://www.ime.unicamp.br/~martinez/packmol/userguide.shtml + Returns ------- solvated : mb.Compound From 6531cf461308127c104f00718447f2af07d28fe8 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 28 May 2024 23:15:07 -0600 Subject: [PATCH 19/22] remove vague test for warning --- mbuild/tests/test_packing.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index 02529fb94..c2c574d49 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -301,10 +301,6 @@ def test_packmol_error(self, h2o): with pytest.raises(MBuildError, match=r"co\-linear"): mb.fill_box(h2o, n_compounds=10, box=[0, 0, 0]) - def test_packmol_warning(self, h2o): - with pytest.warns(UserWarning): - mb.fill_box(h2o, n_compounds=10, box=[1, 1, 1], overlap=10) - def test_packmol_args(self, h2o): with pytest.raises(RuntimeError): mb.fill_box( From 61370b73df044ec0b0bb6cd0b9fb6b9c17738674 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 28 May 2024 23:29:49 -0600 Subject: [PATCH 20/22] fix failing tests --- mbuild/tests/test_compound.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mbuild/tests/test_compound.py b/mbuild/tests/test_compound.py index fc63b4bd5..8064fb8eb 100644 --- a/mbuild/tests/test_compound.py +++ b/mbuild/tests/test_compound.py @@ -634,7 +634,7 @@ def test_mass_property(self, h2o): assert np.allclose(h2o.mass, 18.015, atol=1e-5) - system = mb.fill_box(compound=h2o, n_compounds=5, box=[0.5, 0.5, 0.5]) + system = mb.fill_box(compound=h2o, n_compounds=5, box=[2, 2, 2], seed=32) assert np.allclose(system.mass, 5 * h2o.mass, atol=1e-5) def test_mass_setter(self, ethane): @@ -1471,11 +1471,11 @@ def test_fillbox_then_parmed(self): box = Box.from_mins_maxs_angles( mins=(2, 2, 2), maxs=(3, 3, 3), angles=(90.0, 90.0, 90.0) ) - bead_box = mb.fill_box(bead, 100, box=[2, 2, 2, 3, 3, 3]) + bead_box = mb.fill_box(bead, 50, box=[2, 2, 2, 3, 3, 3], seed=32) bead_box_in_pmd = bead_box.to_parmed(box=box) assert isinstance(bead_box_in_pmd, pmd.Structure) - assert len(bead_box_in_pmd.atoms) == 100 + assert len(bead_box_in_pmd.atoms) == 50 assert ( bead_box_in_pmd.box == np.array([10.0, 10.0, 10.0, 90.0, 90.0, 90.0]) From cfa78b44d1f537edee73f88e8efe65b082c07e70 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 29 May 2024 05:30:07 +0000 Subject: [PATCH 21/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mbuild/tests/test_compound.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mbuild/tests/test_compound.py b/mbuild/tests/test_compound.py index 8064fb8eb..859aa83e0 100644 --- a/mbuild/tests/test_compound.py +++ b/mbuild/tests/test_compound.py @@ -634,7 +634,9 @@ def test_mass_property(self, h2o): assert np.allclose(h2o.mass, 18.015, atol=1e-5) - system = mb.fill_box(compound=h2o, n_compounds=5, box=[2, 2, 2], seed=32) + system = mb.fill_box( + compound=h2o, n_compounds=5, box=[2, 2, 2], seed=32 + ) assert np.allclose(system.mass, 5 * h2o.mass, atol=1e-5) def test_mass_setter(self, ethane): @@ -1475,7 +1477,7 @@ def test_fillbox_then_parmed(self): bead_box_in_pmd = bead_box.to_parmed(box=box) assert isinstance(bead_box_in_pmd, pmd.Structure) - assert len(bead_box_in_pmd.atoms) == 50 + assert len(bead_box_in_pmd.atoms) == 50 assert ( bead_box_in_pmd.box == np.array([10.0, 10.0, 10.0, 90.0, 90.0, 90.0]) From efc1c1c18958558fc6f2a41841b98bec75099a23 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 18:26:17 +0000 Subject: [PATCH 22/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mbuild/tests/test_compound.py | 2 +- mbuild/tests/test_packing.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mbuild/tests/test_compound.py b/mbuild/tests/test_compound.py index 8f5b01efa..3de82bba9 100644 --- a/mbuild/tests/test_compound.py +++ b/mbuild/tests/test_compound.py @@ -1477,7 +1477,7 @@ def test_fillbox_then_parmed(self): bead_box_in_pmd = bead_box.to_parmed(box=box) assert isinstance(bead_box_in_pmd, pmd.Structure) - assert len(bead_box_in_pmd.atoms) == 100 + assert len(bead_box_in_pmd.atoms) == 100 assert ( bead_box_in_pmd.box == np.array([10.0, 10.0, 10.0, 90.0, 90.0, 90.0]) diff --git a/mbuild/tests/test_packing.py b/mbuild/tests/test_packing.py index 5bf2a7f50..a364772b4 100644 --- a/mbuild/tests/test_packing.py +++ b/mbuild/tests/test_packing.py @@ -409,6 +409,7 @@ def test_packmol_args_default(self, args): box=[10, 10, 10], packmol_args=args, ) + def test_packmol_warning(self, h2o): import sys