diff --git a/mosdef_gomc/formats/gmso_gomc_conf_writer.py b/mosdef_gomc/formats/gmso_gomc_conf_writer.py index 56d61234..2ef61280 100644 --- a/mosdef_gomc/formats/gmso_gomc_conf_writer.py +++ b/mosdef_gomc/formats/gmso_gomc_conf_writer.py @@ -2,9 +2,9 @@ import os from warnings import warn +import numpy as np import unyt as u from unyt.dimensions import energy, length, pressure, temperature -import numpy as np from mosdef_gomc.formats.gmso_charmm_writer import Charmm @@ -727,7 +727,7 @@ def _get_all_possible_input_variables(description=False): "running each move, based on the calculated density of the GEMC boxes." "".format(_get_default_variables_dict()["MultiParticleLiquid"]), "MultiParticleGas": "bool, default=False (GEMC-only) : " - "Use the multi-particle moves (MultiParticleFreq and MultiParticleBrownianFreq) " + "Use the multi-particle moves (MultiParticleFreq and MultiParticleBrownianFreq) " "in the gas/vapor phase. " "Note: GOMC determines the boxes are liquid or gas/vapor before " "running each move, based on the calculated density of the GEMC boxes." @@ -4599,10 +4599,12 @@ def __init__( ) if ( - input_var_keys_list[var_iter] == key - and key in possible_ensemble_variables_list + input_var_keys_list[var_iter] == key + and key in possible_ensemble_variables_list ): - self.MultiParticleBrownianFreq = self.input_variables_dict[key] + self.MultiParticleBrownianFreq = self.input_variables_dict[ + key + ] # MEMC moves freqencies key = "IntraMEMC-1Freq" @@ -5982,7 +5984,10 @@ def __init__( print("\t CrankShaftFreq = " + str(self.CrankShaftFreq)) print("\t VolFreq = " + str(self.VolFreq)) print("\t MultiParticleFreq = " + str(self.MultiParticleFreq)) - print("\t MultiParticleBrownianFreq = " + str(self.MultiParticleBrownianFreq)) + print( + "\t MultiParticleBrownianFreq = " + + str(self.MultiParticleBrownianFreq) + ) print("\t IntraMEMC-1Freq = " + str(self.IntraMEMC_1Freq)) print("\t MEMC-1Freq = " + str(self.MEMC_1Freq)) print("\t IntraMEMC-2Freq = " + str(self.IntraMEMC_2Freq)) @@ -6007,7 +6012,9 @@ def __init__( raise ValueError(print_error_message) # MultiParticleFreq and MultiParticleBrownianFreq cannot be used at the same time. - if not np.isclose(self.MultiParticleFreq, 0) and not np.isclose(self.MultiParticleBrownianFreq, 0): + if not np.isclose(self.MultiParticleFreq, 0) and not np.isclose( + self.MultiParticleBrownianFreq, 0 + ): raise ValueError( "ERROR: Both MultiParticle (MultiParticleFreq) and MultiParticleBrownian " "(MultiParticleBrownianFreq) cannot be used at the same time." @@ -6738,8 +6745,10 @@ def write_conf_file(self, conf_filename): data_control_file.write(" \n") # Mulit-particle move in Liquid and vapor/phases - if (not np.isclose(self.MultiParticleFreq, 0) or not np.isclose(self.MultiParticleBrownianFreq, 0)) \ - and self.ensemble_type in [ + if ( + not np.isclose(self.MultiParticleFreq, 0) + or not np.isclose(self.MultiParticleBrownianFreq, 0) + ) and self.ensemble_type in [ "GEMC_NPT", "GEMC_NVT", ]: diff --git a/mosdef_gomc/tests/test_gmso_gomc_conf_writer.py b/mosdef_gomc/tests/test_gmso_gomc_conf_writer.py index 0ea2436b..3ea1aa0f 100644 --- a/mosdef_gomc/tests/test_gmso_gomc_conf_writer.py +++ b/mosdef_gomc/tests/test_gmso_gomc_conf_writer.py @@ -2685,7 +2685,7 @@ def test_save_change_most_variable_GEMC_NPT_bad_mulitparticle_gas_setting( ) def test_save_change_most_variable_GEMC_NVT_mulitparticlebrownian_settings_default( - self, ethane_gomc, ethanol_gomc + self, ethane_gomc, ethanol_gomc ): test_box_ethane_ethanol = mb.fill_box( compound=[ethane_gomc, ethanol_gomc], @@ -2721,8 +2721,8 @@ def test_save_change_most_variable_GEMC_NVT_mulitparticlebrownian_settings_defau ) with open( - "test_save_change_most_variable_GEMC_NVT_mulitparticlebrownian_settings_default.conf", - "r", + "test_save_change_most_variable_GEMC_NVT_mulitparticlebrownian_settings_default.conf", + "r", ) as fp: variables_read_dict = { "MultiParticleLiquid": False, @@ -2748,9 +2748,8 @@ def test_save_change_most_variable_GEMC_NVT_mulitparticlebrownian_settings_defau "MultiParticleGas": True, } - def test_save_change_most_variable_GEMC_NVT_mulitparticlebrownian_settings_both_false( - self, ethane_gomc, ethanol_gomc + self, ethane_gomc, ethanol_gomc ): test_box_ethane_ethanol = mb.fill_box( compound=[ethane_gomc, ethanol_gomc], @@ -2788,8 +2787,8 @@ def test_save_change_most_variable_GEMC_NVT_mulitparticlebrownian_settings_both_ ) with open( - "test_save_change_most_variable_GEMC_NVT_mulitparticlebrownian_settings_both_false.conf", - "r", + "test_save_change_most_variable_GEMC_NVT_mulitparticlebrownian_settings_both_false.conf", + "r", ) as fp: variables_read_dict = { "MultiParticleLiquid": False, @@ -2815,9 +2814,8 @@ def test_save_change_most_variable_GEMC_NVT_mulitparticlebrownian_settings_both_ "MultiParticleGas": True, } - def test_save_change_most_variable_GEMC_NPT_mulitparticlebrownian_settings_both_true( - self, ethane_gomc, ethanol_gomc + self, ethane_gomc, ethanol_gomc ): test_box_ethane_ethanol = mb.fill_box( compound=[ethane_gomc, ethanol_gomc], @@ -2855,8 +2853,8 @@ def test_save_change_most_variable_GEMC_NPT_mulitparticlebrownian_settings_both_ ) with open( - "test_save_change_most_variable_GEMC_NPT_mulitparticlebrownian_settings_both_true.conf", - "r", + "test_save_change_most_variable_GEMC_NPT_mulitparticlebrownian_settings_both_true.conf", + "r", ) as fp: variables_read_dict = { "MultiParticleLiquid": False, @@ -2882,9 +2880,8 @@ def test_save_change_most_variable_GEMC_NPT_mulitparticlebrownian_settings_both_ "MultiParticleGas": True, } - def test_save_change_most_variable_GEMC_NPT_mulitparticlebrownian_not_printed_for_NVT( - self, ethane_gomc, ethanol_gomc + self, ethane_gomc, ethanol_gomc ): test_box_ethane_ethanol = mb.fill_box( compound=[ethane_gomc, ethanol_gomc], @@ -2899,13 +2896,13 @@ def test_save_change_most_variable_GEMC_NPT_mulitparticlebrownian_not_printed_fo forcefield_selection="oplsaa", ) with pytest.raises( - ValueError, - match=r"ERROR: All the correct input variables where not provided for " - r"the NVT ensemble. Please be sure to check that the keys in the " - r"input variables dictionary \(input_variables_dict\) is correct, and " - r"be aware that added spaces before or after the variable in any keys " - r"will also give this warning. The bad variable inputs ensemble " - r"inputs = \['MultiParticleLiquid', 'MultiParticleGas'\]", + ValueError, + match=r"ERROR: All the correct input variables where not provided for " + r"the NVT ensemble. Please be sure to check that the keys in the " + r"input variables dictionary \(input_variables_dict\) is correct, and " + r"be aware that added spaces before or after the variable in any keys " + r"will also give this warning. The bad variable inputs ensemble " + r"inputs = \['MultiParticleLiquid', 'MultiParticleGas'\]", ): gomc_control.write_gomc_control_file( charmm, @@ -2927,9 +2924,8 @@ def test_save_change_most_variable_GEMC_NPT_mulitparticlebrownian_not_printed_fo }, ) - def test_save_change_most_variable_GEMC_NPT_bad_mulitparticlebrownian_liquid_setting( - self, ethane_gomc, ethanol_gomc + self, ethane_gomc, ethanol_gomc ): test_box_ethane_ethanol = mb.fill_box( compound=[ethane_gomc, ethanol_gomc], @@ -2947,11 +2943,11 @@ def test_save_change_most_variable_GEMC_NPT_bad_mulitparticlebrownian_liquid_set ) with pytest.raises( - ValueError, - match=r"ERROR: The following input variables have " - r"bad values \(check spelling and for empty spaces in the keys or that " - r"the values are in the correct form with the acceptable values\)" - r": \['MultiParticleLiquid'\]", + ValueError, + match=r"ERROR: The following input variables have " + r"bad values \(check spelling and for empty spaces in the keys or that " + r"the values are in the correct form with the acceptable values\)" + r": \['MultiParticleLiquid'\]", ): gomc_control.write_gomc_control_file( charmm, @@ -2973,9 +2969,8 @@ def test_save_change_most_variable_GEMC_NPT_bad_mulitparticlebrownian_liquid_set }, ) - def test_save_change_most_variable_GEMC_NPT_bad_mulitparticlebrownian_gas_setting( - self, ethane_gomc, ethanol_gomc + self, ethane_gomc, ethanol_gomc ): test_box_ethane_ethanol = mb.fill_box( compound=[ethane_gomc, ethanol_gomc], @@ -2993,11 +2988,11 @@ def test_save_change_most_variable_GEMC_NPT_bad_mulitparticlebrownian_gas_settin ) with pytest.raises( - ValueError, - match=r"ERROR: The following input variables have " - r"bad values \(check spelling and for empty spaces in the keys or that " - r"the values are in the correct form with the acceptable values\)" - r": \['MultiParticleGas'\]", + ValueError, + match=r"ERROR: The following input variables have " + r"bad values \(check spelling and for empty spaces in the keys or that " + r"the values are in the correct form with the acceptable values\)" + r": \['MultiParticleGas'\]", ): gomc_control.write_gomc_control_file( charmm, @@ -3020,7 +3015,7 @@ def test_save_change_most_variable_GEMC_NPT_bad_mulitparticlebrownian_gas_settin ) def test_save_change_most_variable_GEMC_NPT_bad_mulitparticle_and_mulitparticlebrownian( - self, ethane_gomc, ethanol_gomc + self, ethane_gomc, ethanol_gomc ): test_box_ethane_ethanol = mb.fill_box( compound=[ethane_gomc, ethanol_gomc], @@ -3038,9 +3033,9 @@ def test_save_change_most_variable_GEMC_NPT_bad_mulitparticle_and_mulitparticleb ) with pytest.raises( - ValueError, - match=r"ERROR: Both MultiParticle \(MultiParticleFreq\) and MultiParticleBrownian " - r"\(MultiParticleBrownianFreq\) cannot be used at the same time.", + ValueError, + match=r"ERROR: Both MultiParticle \(MultiParticleFreq\) and MultiParticleBrownian " + r"\(MultiParticleBrownianFreq\) cannot be used at the same time.", ): gomc_control.write_gomc_control_file( charmm, @@ -3064,7 +3059,7 @@ def test_save_change_most_variable_GEMC_NPT_bad_mulitparticle_and_mulitparticleb ) def test_save_GEMC_NPT_bad_mulitparticlebrownian_freq_greater_than_1( - self, ethane_gomc, ethanol_gomc + self, ethane_gomc, ethanol_gomc ): test_box_ethane_ethanol = mb.fill_box( compound=[ethane_gomc, ethanol_gomc], @@ -3082,15 +3077,15 @@ def test_save_GEMC_NPT_bad_mulitparticlebrownian_freq_greater_than_1( ) with pytest.raises( - ValueError, - match= r"ERROR: The sum of the Monte Carlo move ratios does not equal 1. " - r"Note: The sum that was manually entered may equal 1, but some " - r"moves may not be valid for the provided ensemble. The moves " - r"that are invalid for a given ensemble are set to zero. If " - r"the default moves are not being used, all the move frequencies " - r"which do not have default values of zero will need to be set manually " - r"so the sum equals \(DisFreq, RotFreq, IntraSwapFreq, SwapFreq, " - r"RegrowthFreq, CrankShaftFreq, and VolFreq\).", + ValueError, + match=r"ERROR: The sum of the Monte Carlo move ratios does not equal 1. " + r"Note: The sum that was manually entered may equal 1, but some " + r"moves may not be valid for the provided ensemble. The moves " + r"that are invalid for a given ensemble are set to zero. If " + r"the default moves are not being used, all the move frequencies " + r"which do not have default values of zero will need to be set manually " + r"so the sum equals \(DisFreq, RotFreq, IntraSwapFreq, SwapFreq, " + r"RegrowthFreq, CrankShaftFreq, and VolFreq\).", ): gomc_control.write_gomc_control_file( charmm, @@ -16657,4 +16652,4 @@ def test_exp6_with_exp6_conf_config(self, hexane_ua): "Coordinates_box_0": True, "Structure_box_0": True, "Potential": True, - } \ No newline at end of file + }