From 1994a2deedea62dadb886ffd0f5f52f7f8287144 Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Tue, 22 Nov 2022 12:18:38 -0700 Subject: [PATCH 01/13] add better notes about unit conversions --- mbuild/formats/hoomd_forcefield.py | 30 ++++++++++++++++++--- mbuild/formats/hoomd_snapshot.py | 42 +++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/mbuild/formats/hoomd_forcefield.py b/mbuild/formats/hoomd_forcefield.py index 92cad71b0..146796d3b 100644 --- a/mbuild/formats/hoomd_forcefield.py +++ b/mbuild/formats/hoomd_forcefield.py @@ -70,9 +70,33 @@ def create_hoomd_forcefield( ---- If you pass a non-parametrized pmd.Structure, you will not have angle, dihedral, or force field information. You may be better off - creating a hoomd.Snapshot - Reference units should be expected to convert parmed Structure units : - angstroms, kcal/mol, and daltons + creating a hoomd.Snapshot. + + Note about units + ---------------- + This method operates on a Parmed.Structure object where the units used + differ from those used in mBuild and Foyer, which may have used + when creating the typed Parmed.Structure. + + The default units used when writing out the HOOMD Snapshot are: + Distance (Angstrom) + Mass (Dalton) + Energy (kcal/mol) + + If you wish to convert this unit system to another, you can use the + reference parameters (ref_distance, ref_mass, ref_energy) + The values used here should be expected to convert from the Parmed + Structure units (above) to your desired units. + + Examples: The Parmed.Structure values are divided by the reference values + To convert the enregy units from kcal/mol to kj/mol: + use ref_energy = 0.2390057 (kcal/kj) + To convert the distance units from Angstrom to nm: + use ref_distance = 10 (angstroms/nm) + + You can also use the auto_scale parameter to convert distance, energy + and mass to a reduced (unitless) system. + """ if isinstance(structure, mb.Compound): raise ValueError( diff --git a/mbuild/formats/hoomd_snapshot.py b/mbuild/formats/hoomd_snapshot.py index 0031a53c7..b01991e97 100644 --- a/mbuild/formats/hoomd_snapshot.py +++ b/mbuild/formats/hoomd_snapshot.py @@ -77,7 +77,6 @@ def from_snapshot(snapshot, scale=1.0): comp.add(atom, label=str(i)) # Add bonds - particle_dict = {idx: p for idx, p in enumerate(comp.particles())} for i in range(bond_array.shape[0]): atom1 = int(bond_array[i][0]) atom2 = int(bond_array[i][1]) @@ -104,11 +103,11 @@ def to_hoomdsnapshot( structure : parmed.Structure ParmEd Structure object ref_distance : float, optional, default=1.0 - Reference distance for conversion to reduced units + Reference distance for unit conversion (from Angstrom) ref_mass : float, optional, default=1.0 - Reference mass for conversion to reduced units + Reference mass for unit conversion (from Dalton) ref_energy : float, optional, default=1.0 - Reference energy for conversion to reduced units + Reference energy for unit conversion (from kcal/mol) rigid_bodies : list of int, optional, default=None List of rigid body information. An integer value is required for each atom corresponding to the index of the rigid body the particle @@ -133,11 +132,36 @@ def to_hoomdsnapshot( hoomd_snapshot : hoomd.Snapshot ReferenceValues : namedtuple Values used in scaling - - - Notes - ----- - Force field parameters are not written to the hoomd_snapshot + + Note + ----- + This method does not create hoomd forcefield objects, and + the snapshot returned does not store the forcefield parameters. + See mbuild.formts.hoomd_forcefield.create_hoomd_forcefield() + + Note about units + ---------------- + This method operates on a Parmed.Structure object where the units used + differ from those used in mBuild and Foyer, which may have used + when creating the typed Parmed.Structure. + + The default units used when writing out the HOOMD Snapshot are: + Distance (Angstrom) + Mass (Dalton) + Energy (kcal/mol) + + If you wish to convert this unit system to another, you can use the + reference parameters (ref_distance, ref_mass, ref_energy) + The values used here should be expected to convert from the Parmed + Structure units (above) to your desired units. + + Examples: The Parmed.Structure values are divided by the reference values + use ref_energy = 0.2390057 (kcal/kj) + To convert the distance units from Angstrom to nm: + use ref_distance = 10 (angstroms/nm) + + You can also use the auto_scale parameter to convert distance, energy + and mass to a reduced (unitless) system. """ if not isinstance(structure, (Compound, pmd.Structure)): raise ValueError( From 793324a13f3fcd5fdc371a512bde40ba60ad213a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 22 Nov 2022 19:24:46 +0000 Subject: [PATCH 02/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mbuild/formats/hoomd_snapshot.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mbuild/formats/hoomd_snapshot.py b/mbuild/formats/hoomd_snapshot.py index b01991e97..171ecd90b 100644 --- a/mbuild/formats/hoomd_snapshot.py +++ b/mbuild/formats/hoomd_snapshot.py @@ -107,7 +107,7 @@ def to_hoomdsnapshot( ref_mass : float, optional, default=1.0 Reference mass for unit conversion (from Dalton) ref_energy : float, optional, default=1.0 - Reference energy for unit conversion (from kcal/mol) + Reference energy for unit conversion (from kcal/mol) rigid_bodies : list of int, optional, default=None List of rigid body information. An integer value is required for each atom corresponding to the index of the rigid body the particle @@ -132,12 +132,12 @@ def to_hoomdsnapshot( hoomd_snapshot : hoomd.Snapshot ReferenceValues : namedtuple Values used in scaling - - Note - ----- - This method does not create hoomd forcefield objects, and - the snapshot returned does not store the forcefield parameters. - See mbuild.formts.hoomd_forcefield.create_hoomd_forcefield() + + Note + ----- + This method does not create hoomd forcefield objects, and + the snapshot returned does not store the forcefield parameters. + See mbuild.formts.hoomd_forcefield.create_hoomd_forcefield() Note about units ---------------- From 825a95c5fe065c405ab3cd66eeaa739b2006490f Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Tue, 22 Nov 2022 12:25:41 -0700 Subject: [PATCH 03/13] adding a missing word --- mbuild/formats/hoomd_forcefield.py | 4 ++-- mbuild/formats/hoomd_snapshot.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mbuild/formats/hoomd_forcefield.py b/mbuild/formats/hoomd_forcefield.py index 146796d3b..7e72a94e9 100644 --- a/mbuild/formats/hoomd_forcefield.py +++ b/mbuild/formats/hoomd_forcefield.py @@ -75,7 +75,7 @@ def create_hoomd_forcefield( Note about units ---------------- This method operates on a Parmed.Structure object where the units used - differ from those used in mBuild and Foyer, which may have used + differ from those used in mBuild and Foyer, which may have been used when creating the typed Parmed.Structure. The default units used when writing out the HOOMD Snapshot are: @@ -84,7 +84,7 @@ def create_hoomd_forcefield( Energy (kcal/mol) If you wish to convert this unit system to another, you can use the - reference parameters (ref_distance, ref_mass, ref_energy) + reference parameters (ref_distance, ref_mass, ref_energy). The values used here should be expected to convert from the Parmed Structure units (above) to your desired units. diff --git a/mbuild/formats/hoomd_snapshot.py b/mbuild/formats/hoomd_snapshot.py index b01991e97..f07e1bd6f 100644 --- a/mbuild/formats/hoomd_snapshot.py +++ b/mbuild/formats/hoomd_snapshot.py @@ -142,7 +142,7 @@ def to_hoomdsnapshot( Note about units ---------------- This method operates on a Parmed.Structure object where the units used - differ from those used in mBuild and Foyer, which may have used + differ from those used in mBuild and Foyer, which may have been used when creating the typed Parmed.Structure. The default units used when writing out the HOOMD Snapshot are: From eb2a82fefff9d6ee6ab41579126486caf7ac424c Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Tue, 22 Nov 2022 13:45:18 -0700 Subject: [PATCH 04/13] fix a couple formatting issues --- mbuild/formats/hoomd_forcefield.py | 3 ++- mbuild/formats/hoomd_snapshot.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mbuild/formats/hoomd_forcefield.py b/mbuild/formats/hoomd_forcefield.py index 7e72a94e9..8dc492a84 100644 --- a/mbuild/formats/hoomd_forcefield.py +++ b/mbuild/formats/hoomd_forcefield.py @@ -87,8 +87,9 @@ def create_hoomd_forcefield( reference parameters (ref_distance, ref_mass, ref_energy). The values used here should be expected to convert from the Parmed Structure units (above) to your desired units. + The Parmed.Structure values are divided by the reference values. - Examples: The Parmed.Structure values are divided by the reference values + Examples: To convert the enregy units from kcal/mol to kj/mol: use ref_energy = 0.2390057 (kcal/kj) To convert the distance units from Angstrom to nm: diff --git a/mbuild/formats/hoomd_snapshot.py b/mbuild/formats/hoomd_snapshot.py index e5bc9af19..6840aa78e 100644 --- a/mbuild/formats/hoomd_snapshot.py +++ b/mbuild/formats/hoomd_snapshot.py @@ -133,11 +133,11 @@ def to_hoomdsnapshot( ReferenceValues : namedtuple Values used in scaling - Note - ----- - This method does not create hoomd forcefield objects, and - the snapshot returned does not store the forcefield parameters. - See mbuild.formts.hoomd_forcefield.create_hoomd_forcefield() + Note + ----- + This method does not create hoomd forcefield objects, and + the snapshot returned does not store the forcefield parameters. + See mbuild.formts.hoomd_forcefield.create_hoomd_forcefield() Note about units ---------------- @@ -154,14 +154,17 @@ def to_hoomdsnapshot( reference parameters (ref_distance, ref_mass, ref_energy) The values used here should be expected to convert from the Parmed Structure units (above) to your desired units. + The Parmed.Structure values are divided by the reference values - Examples: The Parmed.Structure values are divided by the reference values + Examples: + To convert the energy units from kcal/mol to kj/mol: use ref_energy = 0.2390057 (kcal/kj) To convert the distance units from Angstrom to nm: use ref_distance = 10 (angstroms/nm) You can also use the auto_scale parameter to convert distance, energy and mass to a reduced (unitless) system. + """ if not isinstance(structure, (Compound, pmd.Structure)): raise ValueError( From dbee990df2f7bd24e088374b00a12cc9f6cb1f44 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 22 Nov 2022 20:45:41 +0000 Subject: [PATCH 05/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mbuild/formats/hoomd_snapshot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mbuild/formats/hoomd_snapshot.py b/mbuild/formats/hoomd_snapshot.py index 6840aa78e..0e0fba989 100644 --- a/mbuild/formats/hoomd_snapshot.py +++ b/mbuild/formats/hoomd_snapshot.py @@ -157,7 +157,7 @@ def to_hoomdsnapshot( The Parmed.Structure values are divided by the reference values Examples: - To convert the energy units from kcal/mol to kj/mol: + To convert the energy units from kcal/mol to kj/mol: use ref_energy = 0.2390057 (kcal/kj) To convert the distance units from Angstrom to nm: use ref_distance = 10 (angstroms/nm) From 75685f4803ae1c3fed343f88d6f2af4ad340ed75 Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Tue, 6 Dec 2022 10:28:07 -0700 Subject: [PATCH 06/13] fix typos, clean up formatting --- mbuild/formats/hoomd_forcefield.py | 33 +++++++++++++++----------- mbuild/formats/hoomd_snapshot.py | 37 ++++++++++++++++-------------- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/mbuild/formats/hoomd_forcefield.py b/mbuild/formats/hoomd_forcefield.py index 8dc492a84..47376c413 100644 --- a/mbuild/formats/hoomd_forcefield.py +++ b/mbuild/formats/hoomd_forcefield.py @@ -38,11 +38,11 @@ def create_hoomd_forcefield( r_cut : float Cutoff radius in simulation units ref_distance : float, optional, default=1.0 - Reference distance for unit conversion (from Angstrom) + Reference distance for unit conversion ((Angstrom) / (desired units)) ref_mass : float, optional, default=1.0 - Reference mass for unit conversion (from Dalton) + Reference mass for unit conversion ((Dalton) / (desired units)) ref_energy : float, optional, default=1.0 - Reference energy for unit conversion (from kcal/mol) + Reference energy for unit conversion ((kcal/mol) / (desired units)) auto_scale : bool, optional, default=False Scale to reduced units by automatically using the largest sigma value as ref_distance, largest mass value as ref_mass, and largest epsilon @@ -66,17 +66,16 @@ def create_hoomd_forcefield( ReferenceValues : namedtuple Values used in scaling - Note - ---- + Notes + ----- If you pass a non-parametrized pmd.Structure, you will not have angle, dihedral, or force field information. You may be better off creating a hoomd.Snapshot. + See mbuild.formats.hoomd_snapshot.to_hoomdsnapshot() - Note about units - ---------------- - This method operates on a Parmed.Structure object where the units used - differ from those used in mBuild and Foyer, which may have been used - when creating the typed Parmed.Structure. + About units: This method operates on a Parmed.Structure object + where the units used differ from those used in mBuild and Foyer + which may have been used when creating the typed Parmed.Structure. The default units used when writing out the HOOMD Snapshot are: Distance (Angstrom) @@ -88,15 +87,21 @@ def create_hoomd_forcefield( The values used here should be expected to convert from the Parmed Structure units (above) to your desired units. The Parmed.Structure values are divided by the reference values. + + If you wish to used a reduced unit system, set auto_scale = True. + When auto_scale is True, the reference parameters won't be used. - Examples: - To convert the enregy units from kcal/mol to kj/mol: + Examples + -------- + To convert the energy units from kcal/mol to kj/mol: use ref_energy = 0.2390057 (kcal/kj) + To convert the distance units from Angstrom to nm: use ref_distance = 10 (angstroms/nm) - You can also use the auto_scale parameter to convert distance, energy - and mass to a reduced (unitless) system. + To use a reduced unit system, where mass, sigma, and epsilon are + scaled by the largest value of each: + use auto_scale = True, ref_distance = ref_energy = ref_mass = 1 """ if isinstance(structure, mb.Compound): diff --git a/mbuild/formats/hoomd_snapshot.py b/mbuild/formats/hoomd_snapshot.py index 0e0fba989..460ec325b 100644 --- a/mbuild/formats/hoomd_snapshot.py +++ b/mbuild/formats/hoomd_snapshot.py @@ -102,12 +102,11 @@ def to_hoomdsnapshot( ---------- structure : parmed.Structure ParmEd Structure object - ref_distance : float, optional, default=1.0 - Reference distance for unit conversion (from Angstrom) + Reference distance for unit conversion ((Angstrom) / (desired units)) ref_mass : float, optional, default=1.0 - Reference mass for unit conversion (from Dalton) + Reference mass for unit conversion ((Dalton) / (desired units)) ref_energy : float, optional, default=1.0 - Reference energy for unit conversion (from kcal/mol) + Reference energy for unit conversion ((kcal/mol) / (desired units)) rigid_bodies : list of int, optional, default=None List of rigid body information. An integer value is required for each atom corresponding to the index of the rigid body the particle @@ -133,17 +132,15 @@ def to_hoomdsnapshot( ReferenceValues : namedtuple Values used in scaling - Note + Notes ----- - This method does not create hoomd forcefield objects, and + This method does not create hoomd forcefield objects and the snapshot returned does not store the forcefield parameters. - See mbuild.formts.hoomd_forcefield.create_hoomd_forcefield() + See mbuild.formats.hoomd_forcefield.create_hoomd_forcefield() - Note about units - ---------------- - This method operates on a Parmed.Structure object where the units used - differ from those used in mBuild and Foyer, which may have been used - when creating the typed Parmed.Structure. + About units: This method operates on a Parmed.Structure object + where the units used differ from those used in mBuild and Foyer + which may have been used when creating the typed Parmed.Structure. The default units used when writing out the HOOMD Snapshot are: Distance (Angstrom) @@ -151,19 +148,25 @@ def to_hoomdsnapshot( Energy (kcal/mol) If you wish to convert this unit system to another, you can use the - reference parameters (ref_distance, ref_mass, ref_energy) + reference parameters (ref_distance, ref_mass, ref_energy). The values used here should be expected to convert from the Parmed Structure units (above) to your desired units. - The Parmed.Structure values are divided by the reference values + The Parmed.Structure values are divided by the reference values. + + If you wish to used a reduced unit system, set auto_scale = True. + When auto_scale is True, the reference parameters won't be used. - Examples: + Examples + -------- To convert the energy units from kcal/mol to kj/mol: use ref_energy = 0.2390057 (kcal/kj) + To convert the distance units from Angstrom to nm: use ref_distance = 10 (angstroms/nm) - You can also use the auto_scale parameter to convert distance, energy - and mass to a reduced (unitless) system. + To use a reduced unit system, where mass, sigma, and epsilon are + scaled by the largest value of each: + use auto_scale = True, ref_distance = ref_energy = ref_mass = 1 """ if not isinstance(structure, (Compound, pmd.Structure)): From 705365754d571168934b6251aa8e46bd5ff18c34 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 Dec 2022 17:28:27 +0000 Subject: [PATCH 07/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mbuild/formats/hoomd_forcefield.py | 2 +- mbuild/formats/hoomd_snapshot.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mbuild/formats/hoomd_forcefield.py b/mbuild/formats/hoomd_forcefield.py index 47376c413..31e61d5db 100644 --- a/mbuild/formats/hoomd_forcefield.py +++ b/mbuild/formats/hoomd_forcefield.py @@ -87,7 +87,7 @@ def create_hoomd_forcefield( The values used here should be expected to convert from the Parmed Structure units (above) to your desired units. The Parmed.Structure values are divided by the reference values. - + If you wish to used a reduced unit system, set auto_scale = True. When auto_scale is True, the reference parameters won't be used. diff --git a/mbuild/formats/hoomd_snapshot.py b/mbuild/formats/hoomd_snapshot.py index 460ec325b..a9ff1100d 100644 --- a/mbuild/formats/hoomd_snapshot.py +++ b/mbuild/formats/hoomd_snapshot.py @@ -139,8 +139,8 @@ def to_hoomdsnapshot( See mbuild.formats.hoomd_forcefield.create_hoomd_forcefield() About units: This method operates on a Parmed.Structure object - where the units used differ from those used in mBuild and Foyer - which may have been used when creating the typed Parmed.Structure. + where the units used differ from those used in mBuild and Foyer + which may have been used when creating the typed Parmed.Structure. The default units used when writing out the HOOMD Snapshot are: Distance (Angstrom) From a36284feb76539d249edcd84c320e050cfd6f73b Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Wed, 26 Apr 2023 16:27:40 -0600 Subject: [PATCH 08/13] add static method for particle charge to reduce warnings --- mbuild/compound.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mbuild/compound.py b/mbuild/compound.py index e39c03ac8..1a12374eb 100644 --- a/mbuild/compound.py +++ b/mbuild/compound.py @@ -547,6 +547,8 @@ def mass(self, value): @property def charge(self): """Get the charge of the Compound.""" + if self._contains_only_ports(): + return self._particle_charge(self) charges = [p._charge for p in self.particles()] if None in charges: warn( @@ -554,6 +556,13 @@ def charge(self): "They will not be accounted for during this calculation." ) filtered_charges = [charge for charge in charges if charge is not None] + + @staticmethod + def _particle_charge(particle): + if particle._charge is not None: + return particle._charge + else: + return None return sum(filtered_charges) if filtered_charges else None @charge.setter From 67d82545656efc346a6060d8eec00e4d950d6484 Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Wed, 26 Apr 2023 16:33:56 -0600 Subject: [PATCH 09/13] fix return statement line --- mbuild/compound.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mbuild/compound.py b/mbuild/compound.py index 1a12374eb..2e25b2096 100644 --- a/mbuild/compound.py +++ b/mbuild/compound.py @@ -556,6 +556,7 @@ def charge(self): "They will not be accounted for during this calculation." ) filtered_charges = [charge for charge in charges if charge is not None] + return sum(filtered_charges) if filtered_charges else None @staticmethod def _particle_charge(particle): @@ -563,7 +564,6 @@ def _particle_charge(particle): return particle._charge else: return None - return sum(filtered_charges) if filtered_charges else None @charge.setter def charge(self, value): From 66a16969235d01e2d0b378b1036a749b5c05fc1e Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Thu, 27 Apr 2023 12:37:37 -0600 Subject: [PATCH 10/13] add doc strings, add if statement to check for children --- mbuild/compound.py | 23 +++++++++++++++-------- mbuild/tests/test_compound.py | 7 +++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/mbuild/compound.py b/mbuild/compound.py index 2e25b2096..d014673e2 100644 --- a/mbuild/compound.py +++ b/mbuild/compound.py @@ -274,9 +274,10 @@ def _n_particles(self, include_ports=False): return sum(1 for _ in self._particles(include_ports)) def _contains_only_ports(self): - for part in self.children: - if not part.port_particle: - return False + if self.children: + for part in self.children: + if not part.port_particle: + return False return True def print_hierarchy(self, print_full=False, index=None, show_tree=True): @@ -546,7 +547,15 @@ def mass(self, value): @property def charge(self): - """Get the charge of the Compound.""" + """Return the total charge of a compound. + + If the compound contains children compouds, the total charge of all + children compounds is returned. + + If the charge of a particle has not been explicitly set + then the particle's charge is None, and are not used when + calculating the total charge. + """ if self._contains_only_ports(): return self._particle_charge(self) charges = [p._charge for p in self.particles()] @@ -560,10 +569,8 @@ def charge(self): @staticmethod def _particle_charge(particle): - if particle._charge is not None: - return particle._charge - else: - return None + """Returns charge of a Compound with no children""" + return particle._charge @charge.setter def charge(self, value): diff --git a/mbuild/tests/test_compound.py b/mbuild/tests/test_compound.py index d82a88714..d44b3f228 100644 --- a/mbuild/tests/test_compound.py +++ b/mbuild/tests/test_compound.py @@ -1589,16 +1589,15 @@ def test_charge_neutrality_warn(self, benzene): def test_none_charge(self): A = mb.Compound() - with pytest.warns(UserWarning): - A.charge + assert A.charge == None A.charge = 1 B = mb.Compound() container = mb.Compound(subcompounds=[A, B]) + assert A.charge == 1 + assert B.charge == None with pytest.warns(UserWarning): container_charge = container.charge - assert A.charge == 1 - assert B.charge == None assert container_charge == 1 @pytest.mark.skipif(not has_openbabel, reason="Open Babel not installed") From 7ac9a65c909b399941d6a5e07fa6a6a843037a54 Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Thu, 27 Apr 2023 13:02:21 -0600 Subject: [PATCH 11/13] change == to is --- mbuild/tests/test_compound.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mbuild/tests/test_compound.py b/mbuild/tests/test_compound.py index d44b3f228..cdc828a30 100644 --- a/mbuild/tests/test_compound.py +++ b/mbuild/tests/test_compound.py @@ -1589,13 +1589,13 @@ def test_charge_neutrality_warn(self, benzene): def test_none_charge(self): A = mb.Compound() - assert A.charge == None + assert A.charge is None A.charge = 1 B = mb.Compound() container = mb.Compound(subcompounds=[A, B]) assert A.charge == 1 - assert B.charge == None + assert B.charge is None with pytest.warns(UserWarning): container_charge = container.charge assert container_charge == 1 From 046955242244a2ebdd378dd8241a6e67dbd863e8 Mon Sep 17 00:00:00 2001 From: Co Quach Date: Fri, 28 Apr 2023 14:24:42 -0500 Subject: [PATCH 12/13] fix docstyle --- mbuild/compound.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mbuild/compound.py b/mbuild/compound.py index d014673e2..f79678d5d 100644 --- a/mbuild/compound.py +++ b/mbuild/compound.py @@ -511,7 +511,8 @@ def mass(self): if self._contains_only_ports(): return self._particle_mass(self) else: - particle_masses = [self._particle_mass(p) for p in self.particles()] + particle_masses = [self._particle_mass( + p) for p in self.particles()] if None in particle_masses: warn( f"Some particle of {self} does not have mass." @@ -569,7 +570,7 @@ def charge(self): @staticmethod def _particle_charge(particle): - """Returns charge of a Compound with no children""" + """Return charge of a Compound with no children.""" return particle._charge @charge.setter @@ -1875,7 +1876,7 @@ def _visualize_nglview(self, show_ports=False, color_scheme={}): mdtraj = import_("mdtraj") from mdtraj.geometry.sasa import _ATOMIC_RADII - remove_digits = lambda x: "".join( + def remove_digits(x): return "".join( i for i in x if not i.isdigit() or i == "_" ) for particle in self.particles(): @@ -2424,7 +2425,8 @@ def _check_openbabel_constraints( if not isinstance(part, Compound): raise MBuildError(f"{part} is not a Compound.") if id(part) != id(self) and id(part) not in successors_list: - raise MBuildError(f"{part} is not a member of Compound {self}.") + raise MBuildError( + f"{part} is not a member of Compound {self}.") if check_if_particle: if len(part.children) != 0: @@ -2570,8 +2572,10 @@ def _energy_minimize_openbabel( f"Cannot create a constraint between a Particle and itself: {p1} {p2} ." ) - pid_1 = particle_idx[id(p1)] + 1 # openbabel indices start at 1 - pid_2 = particle_idx[id(p2)] + 1 # openbabel indices start at 1 + # openbabel indices start at 1 + pid_1 = particle_idx[id(p1)] + 1 + # openbabel indices start at 1 + pid_2 = particle_idx[id(p2)] + 1 dist = ( con_temp[1] * 10.0 ) # obenbabel uses angstroms, not nm, convert to angstroms @@ -2669,7 +2673,8 @@ def _energy_minimize_openbabel( # Since the ignore_compounds can only be passed as a list # we can check the whole list at once before looping over it - self._check_openbabel_constraints(ignore_compounds, successors_list) + self._check_openbabel_constraints( + ignore_compounds, successors_list) for ignore in ignore_compounds: p1 = ignore @@ -3319,7 +3324,8 @@ def __getitem__(self, selection): return list(self.particles())[selection] if isinstance(selection, str): if selection not in self.labels: - raise MBuildError(f"{self.name}['{selection}'] does not exist.") + raise MBuildError( + f"{self.name}['{selection}'] does not exist.") return self.labels.get(selection) def __repr__(self): From 443e92e8c68ccb0278a9b837a72fa1a38ea6416f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 19:25:36 +0000 Subject: [PATCH 13/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mbuild/compound.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/mbuild/compound.py b/mbuild/compound.py index f79678d5d..c85681420 100644 --- a/mbuild/compound.py +++ b/mbuild/compound.py @@ -511,8 +511,7 @@ def mass(self): if self._contains_only_ports(): return self._particle_mass(self) else: - particle_masses = [self._particle_mass( - p) for p in self.particles()] + particle_masses = [self._particle_mass(p) for p in self.particles()] if None in particle_masses: warn( f"Some particle of {self} does not have mass." @@ -1876,9 +1875,9 @@ def _visualize_nglview(self, show_ports=False, color_scheme={}): mdtraj = import_("mdtraj") from mdtraj.geometry.sasa import _ATOMIC_RADII - def remove_digits(x): return "".join( - i for i in x if not i.isdigit() or i == "_" - ) + def remove_digits(x): + return "".join(i for i in x if not i.isdigit() or i == "_") + for particle in self.particles(): particle.name = remove_digits(particle.name).upper() if not particle.name: @@ -2425,8 +2424,7 @@ def _check_openbabel_constraints( if not isinstance(part, Compound): raise MBuildError(f"{part} is not a Compound.") if id(part) != id(self) and id(part) not in successors_list: - raise MBuildError( - f"{part} is not a member of Compound {self}.") + raise MBuildError(f"{part} is not a member of Compound {self}.") if check_if_particle: if len(part.children) != 0: @@ -2673,8 +2671,7 @@ def _energy_minimize_openbabel( # Since the ignore_compounds can only be passed as a list # we can check the whole list at once before looping over it - self._check_openbabel_constraints( - ignore_compounds, successors_list) + self._check_openbabel_constraints(ignore_compounds, successors_list) for ignore in ignore_compounds: p1 = ignore @@ -3324,8 +3321,7 @@ def __getitem__(self, selection): return list(self.particles())[selection] if isinstance(selection, str): if selection not in self.labels: - raise MBuildError( - f"{self.name}['{selection}'] does not exist.") + raise MBuildError(f"{self.name}['{selection}'] does not exist.") return self.labels.get(selection) def __repr__(self):