From b087be766a6e848797fe9c0250fd50c5a065d38f Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Tue, 19 Sep 2023 15:45:37 -0600 Subject: [PATCH 01/12] upgrade hoomd version to 4.1 --- environment-cpu.yml | 2 +- environment-gpu.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/environment-cpu.yml b/environment-cpu.yml index ea9505c3..e9401deb 100644 --- a/environment-cpu.yml +++ b/environment-cpu.yml @@ -6,7 +6,7 @@ dependencies: - foyer - freud - gsd<3.0 - - hoomd=3.11=*cpu* + - hoomd=4.1=*cpu* - mbuild - numpy - openbabel diff --git a/environment-gpu.yml b/environment-gpu.yml index 479e933e..6801c53d 100644 --- a/environment-gpu.yml +++ b/environment-gpu.yml @@ -6,7 +6,7 @@ dependencies: - foyer - freud - gsd<3.0 - - hoomd=3.11=*gpu* + - hoomd=4.1=*gpu* - mbuild - numpy - openbabel From 831d6c410d2d42372b33594fa7a08b363f1d0fd7 Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Tue, 19 Sep 2023 15:45:51 -0600 Subject: [PATCH 02/12] Add thermostats types --- hoomd_organics/utils/__init__.py | 2 +- hoomd_organics/utils/base_types.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hoomd_organics/utils/__init__.py b/hoomd_organics/utils/__init__.py index 9558082f..c2f8fe48 100644 --- a/hoomd_organics/utils/__init__.py +++ b/hoomd_organics/utils/__init__.py @@ -1,5 +1,5 @@ from .actions import * -from .base_types import FF_Types +from .base_types import FF_Types, HOOMDThermostats from .ff_utils import xml_to_gmso_ff from .utils import ( calculate_box_length, diff --git a/hoomd_organics/utils/base_types.py b/hoomd_organics/utils/base_types.py index 4eea254e..8bef2646 100644 --- a/hoomd_organics/utils/base_types.py +++ b/hoomd_organics/utils/base_types.py @@ -1,3 +1,6 @@ +import hoomd + + class FF_Types: opls = "opls" pps_opls = "pps_opls" @@ -5,3 +8,9 @@ class FF_Types: gaff = "gaff" custom = "custom" Hoomd = "Hoomd" + + +class HOOMDThermostats: + BERENDSEN = hoomd.md.methods.thermostats.Berendsen + BUSSI = hoomd.md.methods.thermostats.Bussi + MTTK = hoomd.md.methods.thermostats.MTTK From 2ba23d0f749c8356d7c81d48a31d4cd148b70070 Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Tue, 19 Sep 2023 15:46:13 -0600 Subject: [PATCH 03/12] add thermostat property to simulation --- hoomd_organics/base/simulation.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hoomd_organics/base/simulation.py b/hoomd_organics/base/simulation.py index 6d1defe1..14981620 100644 --- a/hoomd_organics/base/simulation.py +++ b/hoomd_organics/base/simulation.py @@ -8,6 +8,7 @@ import unyt as u from hoomd_organics.utils import ( + HOOMDThermostats, StdOutLogger, UpdateWalls, calculate_box_length, @@ -95,6 +96,7 @@ def __init__( self._create_state(self.initial_state) # Add a gsd and thermo props logger to sim operations self._add_hoomd_writers() + self._thermostat = HOOMDThermostats.BUSSI @classmethod def from_system(cls, system, **kwargs): @@ -281,6 +283,20 @@ def method(self): "have been called for the first time." ) + @property + def thermostat(self): + return self._thermostat + + @thermostat.setter + def thermostat(self, thermostat): + if not issubclass( + self._thermostat, hoomd.md.methods.thermostats.Thermostat + ): + raise ValueError( + f"Invalid thermostat. Please choose from: {HOOMDThermostats}" + ) + self._thermostat = thermostat + def add_force(self, hoomd_force): """""" self._forcefield.append(hoomd_force) From 3b1fa4711adb5740cc5c045ba7b6c838310422ca Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Tue, 19 Sep 2023 17:20:05 -0600 Subject: [PATCH 04/12] update thermostat setup. --- hoomd_organics/base/simulation.py | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/hoomd_organics/base/simulation.py b/hoomd_organics/base/simulation.py index 14981620..ab7a40be 100644 --- a/hoomd_organics/base/simulation.py +++ b/hoomd_organics/base/simulation.py @@ -1,3 +1,4 @@ +import inspect import pickle import warnings @@ -333,6 +334,17 @@ def adjust_sigma(self, scale_by=None, shift_by=None, type_filter=None): elif shift_by: lj_forces.params[k]["sigma"] = sigma + shift_by + def _initialize_thermostat(self, thermostat_kwargs): + """Initializes the thermostat used by the integrator.""" + required_thermostat_kwargs = {} + for k in inspect.signature(self.thermostat).parameters: + if k not in thermostat_kwargs.keys(): + raise ValueError( + f"Missing required parameter {k} for thermostat." + ) + required_thermostat_kwargs[k] = thermostat_kwargs[k] + return self.thermostat(**required_thermostat_kwargs) + def set_integrator_method(self, integrator_method, method_kwargs): """Creates an initial (or updates the existing) method used by Hoomd's integrator. This doesn't need to be called directly; @@ -474,11 +486,12 @@ def run_update_volume( ) self.operations.updaters.append(box_resizer) self.set_integrator_method( - integrator_method=hoomd.md.methods.NVT, + integrator_method=hoomd.md.methods.ConstantVolume, method_kwargs={ - "tau": tau_kt, + "thermostat": self._initialize_thermostat( + {"kT": kT, "tau": tau_kt} + ), "filter": self.integrate_group, - "kT": kT, }, ) if thermalize_particles: @@ -503,7 +516,6 @@ def run_langevin( self, n_steps, kT, - alpha, tally_reservoir_energy=False, default_gamma=1.0, default_gamma_r=(1.0, 1.0, 1.0), @@ -516,7 +528,6 @@ def run_langevin( method_kwargs={ "filter": self.integrate_group, "kT": kT, - "alpha": alpha, "tally_reservoir_energy": tally_reservoir_energy, "default_gamma": default_gamma, "default_gamma_r": default_gamma_r, @@ -549,18 +560,18 @@ def run_NPT( ): """""" self.set_integrator_method( - integrator_method=hoomd.md.methods.NPT, + integrator_method=hoomd.md.methods.ConstantPressure, method_kwargs={ - "kT": kT, "S": pressure, - "tau": tau_kt, "tauS": tau_pressure, "couple": couple, "box_dof": box_dof, "rescale_all": rescale_all, "gamma": gamma, "filter": self.integrate_group, - "kT": kT, + "thermostat": self._initialize_thermostat( + {"kT": kT, "tau": tau_kt} + ), }, ) if thermalize_particles: @@ -584,11 +595,12 @@ def run_NVT( ): """""" self.set_integrator_method( - integrator_method=hoomd.md.methods.NVT, + integrator_method=hoomd.md.methods.ConstantVolume, method_kwargs={ - "tau": tau_kt, + "thermostat": self._initialize_thermostat( + {"kT": kT, "tau": tau_kt} + ), "filter": self.integrate_group, - "kT": kT, }, ) if thermalize_particles: @@ -605,7 +617,7 @@ def run_NVT( def run_NVE(self, n_steps, write_at_start=True): """""" self.set_integrator_method( - integrator_method=hoomd.md.methods.NVE, + integrator_method=hoomd.md.methods.ConstantVolume, method_kwargs={"filter": self.integrate_group}, ) std_out_logger = StdOutLogger(n_steps=n_steps, sim=self) From 32fe78f60ce51f280b781212da7f06e86eb3bbd4 Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Tue, 19 Sep 2023 17:20:25 -0600 Subject: [PATCH 05/12] update unit tests according to recent changes of simulation. --- hoomd_organics/tests/base/test_simulation.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hoomd_organics/tests/base/test_simulation.py b/hoomd_organics/tests/base/test_simulation.py index 65fd40c2..a1dae2f0 100644 --- a/hoomd_organics/tests/base/test_simulation.py +++ b/hoomd_organics/tests/base/test_simulation.py @@ -98,7 +98,7 @@ def test_set_ref_mass(self, benzene_system): def test_NVT(self, benzene_system): sim = Simulation.from_system(benzene_system) sim.run_NVT(kT=1.0, tau_kt=0.01, n_steps=500) - assert isinstance(sim.method, hoomd.md.methods.NVT) + assert isinstance(sim.method, hoomd.md.methods.ConstantVolume) def test_NPT(self, benzene_system): sim = Simulation.from_system(benzene_system) @@ -109,17 +109,17 @@ def test_NPT(self, benzene_system): tau_kt=0.001, tau_pressure=0.01, ) - assert isinstance(sim.method, hoomd.md.methods.NPT) + assert isinstance(sim.method, hoomd.md.methods.ConstantPressure) def test_langevin(self, benzene_system): sim = Simulation.from_system(benzene_system) - sim.run_langevin(n_steps=500, kT=1.0, alpha=0.5) + sim.run_langevin(n_steps=500, kT=1.0) assert isinstance(sim.method, hoomd.md.methods.Langevin) def test_NVE(self, benzene_system): sim = Simulation.from_system(benzene_system) sim.run_NVE(n_steps=500) - assert isinstance(sim.method, hoomd.md.methods.NVE) + assert isinstance(sim.method, hoomd.md.methods.ConstantVolume) def test_displacement_cap(self, benzene_system): sim = Simulation.from_system(benzene_system) @@ -206,11 +206,11 @@ def test_update_volume_two_values(self, benzene_system): def test_change_methods(self, benzene_system): sim = Simulation.from_system(benzene_system) sim.run_NVT(kT=1.0, tau_kt=0.01, n_steps=0) - assert isinstance(sim.method, hoomd.md.methods.NVT) + assert isinstance(sim.method, hoomd.md.methods.ConstantVolume) sim.run_NPT( kT=1.0, tau_kt=0.01, tau_pressure=0.1, pressure=0.001, n_steps=0 ) - assert isinstance(sim.method, hoomd.md.methods.NPT) + assert isinstance(sim.method, hoomd.md.methods.ConstantPressure) def test_change_dt(self, benzene_system): sim = Simulation.from_system(benzene_system) From 6b301edf6fed29915e139e3973253e2c91853efb Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Wed, 20 Sep 2023 11:01:09 -0600 Subject: [PATCH 06/12] change NVE to constantVolume --- hoomd_organics/library/simulations/tensile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hoomd_organics/library/simulations/tensile.py b/hoomd_organics/library/simulations/tensile.py index 0ce5bc1c..19aef409 100644 --- a/hoomd_organics/library/simulations/tensile.py +++ b/hoomd_organics/library/simulations/tensile.py @@ -91,7 +91,7 @@ def run_tensile(self, strain, kT, n_steps, period): self.operations.updaters.append(box_resizer) self.operations.updaters.append(particle_updater) self.set_integrator_method( - integrator_method=hoomd.md.methods.NVE, + integrator_method=hoomd.md.methods.ConstantVolume, method_kwargs={"filter": self.integrate_group}, ) self.run(n_steps + 1) From 124831f8d5a97317e3d8a84fc5370aca1dd70b5f Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Wed, 20 Sep 2023 14:08:44 -0600 Subject: [PATCH 07/12] add filter to gsdwriter --- hoomd_organics/base/simulation.py | 3 ++- hoomd_organics/tests/base/sim_data.txt | 0 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 hoomd_organics/tests/base/sim_data.txt diff --git a/hoomd_organics/base/simulation.py b/hoomd_organics/base/simulation.py index 2980d88a..c46db2f2 100644 --- a/hoomd_organics/base/simulation.py +++ b/hoomd_organics/base/simulation.py @@ -739,7 +739,8 @@ def _add_hoomd_writers(self): filename=self.gsd_file_name, trigger=hoomd.trigger.Periodic(int(self.gsd_write_freq)), mode="wb", - dynamic=["momentum"], + dynamic=["momentum", "property"], + filter=self.integrate_group, logger=gsd_logger, ) diff --git a/hoomd_organics/tests/base/sim_data.txt b/hoomd_organics/tests/base/sim_data.txt deleted file mode 100644 index e69de29b..00000000 From 495d373c209480e8544651b4ff4609f4f79affd4 Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Wed, 20 Sep 2023 14:09:04 -0600 Subject: [PATCH 08/12] flush gsdwriter --- hoomd_organics/tests/base/test_simulation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hoomd_organics/tests/base/test_simulation.py b/hoomd_organics/tests/base/test_simulation.py index b4b903b3..76fa7112 100644 --- a/hoomd_organics/tests/base/test_simulation.py +++ b/hoomd_organics/tests/base/test_simulation.py @@ -309,6 +309,7 @@ def test_save_restart_gsd(self, benzene_system): def test_gsd_logger(self, benzene_system): sim = Simulation.from_system(benzene_system, gsd_write_freq=1) sim.run_NVT(n_steps=5, kT=1.0, tau_kt=0.001) + sim.operations.writers[-2].flush() expected_gsd_quantities = [ "hoomd_organics/base/simulation/Simulation/timestep", "hoomd_organics/base/simulation/Simulation/tps", From d96f0754d49e76e8f0f731932f8c44c4124b4a6c Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Wed, 20 Sep 2023 14:27:37 -0600 Subject: [PATCH 09/12] upgrade to hoomd4.2 --- environment-cpu.yml | 2 +- environment-gpu.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/environment-cpu.yml b/environment-cpu.yml index e9401deb..14509578 100644 --- a/environment-cpu.yml +++ b/environment-cpu.yml @@ -6,7 +6,7 @@ dependencies: - foyer - freud - gsd<3.0 - - hoomd=4.1=*cpu* + - hoomd=4.2=*cpu* - mbuild - numpy - openbabel diff --git a/environment-gpu.yml b/environment-gpu.yml index 6801c53d..547b4a7e 100644 --- a/environment-gpu.yml +++ b/environment-gpu.yml @@ -6,7 +6,7 @@ dependencies: - foyer - freud - gsd<3.0 - - hoomd=4.1=*gpu* + - hoomd=4.2=*gpu* - mbuild - numpy - openbabel From 1eea4337872970e810a19d1c195a5a804407205d Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Wed, 20 Sep 2023 14:37:47 -0600 Subject: [PATCH 10/12] pin hoomd version to 4.1 --- environment-cpu.yml | 2 +- environment-gpu.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/environment-cpu.yml b/environment-cpu.yml index 14509578..e9401deb 100644 --- a/environment-cpu.yml +++ b/environment-cpu.yml @@ -6,7 +6,7 @@ dependencies: - foyer - freud - gsd<3.0 - - hoomd=4.2=*cpu* + - hoomd=4.1=*cpu* - mbuild - numpy - openbabel diff --git a/environment-gpu.yml b/environment-gpu.yml index 547b4a7e..6801c53d 100644 --- a/environment-gpu.yml +++ b/environment-gpu.yml @@ -6,7 +6,7 @@ dependencies: - foyer - freud - gsd<3.0 - - hoomd=4.2=*gpu* + - hoomd=4.1=*gpu* - mbuild - numpy - openbabel From 276988578937f037f58e6a0e7846aedb3177185b Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Wed, 20 Sep 2023 15:01:18 -0600 Subject: [PATCH 11/12] set default thermostat to MTTK --- hoomd_organics/base/simulation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hoomd_organics/base/simulation.py b/hoomd_organics/base/simulation.py index c46db2f2..6579ddd5 100644 --- a/hoomd_organics/base/simulation.py +++ b/hoomd_organics/base/simulation.py @@ -68,6 +68,7 @@ def __init__( gsd_file_name="trajectory.gsd", log_write_freq=1e3, log_file_name="sim_data.txt", + thermostat=HOOMDThermostats.MTTK, ): super(Simulation, self).__init__(device, seed) self.initial_state = initial_state @@ -97,7 +98,7 @@ def __init__( self._create_state(self.initial_state) # Add a gsd and thermo props logger to sim operations self._add_hoomd_writers() - self._thermostat = HOOMDThermostats.BUSSI + self._thermostat = thermostat @classmethod def from_system(cls, system, **kwargs): From 33b5a8fd09ced450834541d2a2cb059d6af31a3f Mon Sep 17 00:00:00 2001 From: marjanalbouye Date: Wed, 20 Sep 2023 15:02:15 -0600 Subject: [PATCH 12/12] use All filter for writer --- hoomd_organics/base/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hoomd_organics/base/simulation.py b/hoomd_organics/base/simulation.py index 6579ddd5..2195b006 100644 --- a/hoomd_organics/base/simulation.py +++ b/hoomd_organics/base/simulation.py @@ -741,7 +741,7 @@ def _add_hoomd_writers(self): trigger=hoomd.trigger.Periodic(int(self.gsd_write_freq)), mode="wb", dynamic=["momentum", "property"], - filter=self.integrate_group, + filter=hoomd.filter.All(), logger=gsd_logger, )