Skip to content

Commit

Permalink
Fix issue with complex dimensionality, clean typos and notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-blanco committed Apr 1, 2024
1 parent 53fdc13 commit 8e49676
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
19 changes: 11 additions & 8 deletions pyMBE.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,18 @@ def check_dimensionality(self, variable, expected_dimensionality):
Args:
`variable`(`pint.Quantity`): Quantity to be checked.
`expected_dimensionality(`str`): Expected dimension of the variable.
"""
try:
correct_dimensionality=variable.check(f"[{expected_dimensionality}]")
except:
raise ValueError(f"The variable {variable} should be a `pint.Quantity` object, instead the variable is {type(variable)}")

Returns:
`bool`: `True` if the variable if of the expected dimensionality, `False` otherwise.
Note:
- `expected_dimensionality` takes dimensionality following the Pint standards [docs](https://pint.readthedocs.io/en/0.10.1/wrapping.html?highlight=dimensionality#checking-dimensionality).
- For example, to check for a variable corresponding to a velocity `expected_dimensionality = "[length]/[time]"`
"""
correct_dimensionality=variable.check(f"{expected_dimensionality}")
if not correct_dimensionality:
raise ValueError(f"The variable {variable} should have a dimensionality of {expected_dimensionality}, instead the variable has a dimensionality of {variable.dimensionality}")
return correct_dimensionality

def check_if_df_cell_has_a_value(self, index,key):
"""
Expand Down Expand Up @@ -2706,7 +2709,7 @@ def setup_lj_interactions(self, espresso_system, shift_potential=True, combining
Args:
espresso_system(`obj`): Instance of a system object from the espressomd library.
shift_potential(`bool`, optional): If True, a shift will be automatically computed such that the potential is continuous at the cutoff radius. Otherwise, no shift will be applied. Defaults to True.
combining_rule(`string`, optional): combining rule used to calculate `sigma` and `epsilon` for the potential betwen a pair of particles. Defaults to 'Lorentz-Berthelot'.
combining_rule(`string`, optional): combining rule used to calculate `sigma` and `epsilon` for the potential between a pair of particles. Defaults to 'Lorentz-Berthelot'.
warning(`bool`, optional): switch to activate/deactivate warning messages. Defaults to True.
Note:
Expand Down Expand Up @@ -2749,7 +2752,7 @@ def setup_lj_interactions(self, espresso_system, shift_potential=True, combining
for ptype in type_pair:
for key in lj_parameters_keys:
lj_parameters[key].append(self.find_value_from_es_type(es_type=ptype, column_name=key))
# If one of the particle has sigma=0, no LJ interations are setuo between that particle type and the others
# If one of the particle has sigma=0, no LJ interations are set up between that particle type and the others
if not all([ sigma_value.magnitude for sigma_value in lj_parameters["sigma"]]):
continue
# Apply combining rule
Expand Down
16 changes: 9 additions & 7 deletions samples/Beyer2024/peptide.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
pmb.load_pka_set (filename='parameters/pka_sets/CRC1991.txt')
model = '2beadAA' # Model with 2 beads per each aminoacid
N_peptide_chains = 4
sigma_Na=0.35*pmb.units.nm
sigma_Cl=0.35*pmb.units.nm
sigma_cation=0.35*pmb.units.nm
sigma_anion=0.35*pmb.units.nm
c_salt=1e-2 * pmb.units.mol/ pmb.units.L
chain_length=len(sequence)*2

Expand All @@ -81,8 +81,8 @@
model = '1beadAA'
N_peptide_chains = 1
c_salt = 5e-3 * pmb.units.mol/ pmb.units.L
sigma_Na=0.2*pmb.units.nm
sigma_Cl=0.36*pmb.units.nm
sigma_cation=0.2*pmb.units.nm
sigma_anion=0.36*pmb.units.nm
chain_length=len(sequence)

# Simulation parameters
Expand All @@ -101,7 +101,9 @@
raise RuntimeError()


pmb.define_peptide (name=sequence, sequence=sequence, model=model)
pmb.define_peptide (name=sequence,
sequence=sequence,
model=model)

# Solution parameters
cation_name = 'Na'
Expand All @@ -110,12 +112,12 @@

pmb.define_particle(name=cation_name,
q=1,
sigma=sigma_Na,
sigma=sigma_cation,
epsilon=1*pmb.units('reduced_energy'))

pmb.define_particle(name=anion_name,
q=-1,
sigma=sigma_Cl,
sigma=sigma_anion,
epsilon=1*pmb.units('reduced_energy'))

# System parameters
Expand Down
2 changes: 1 addition & 1 deletion testsuite/lj_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
verbose=True)
print(f"*** Unit test passed ***")

print(f"*** Unit test: test that setup_lj_interactions does not setup any LJ interactions for particles with sigma = 0 ***")
print(f"*** Unit test: test that setup_lj_interactions does not set up any LJ interactions for particles with sigma = 0 ***")

lj_labels=pmb.filter_df("LennardJones")["name"].values
# Check that no interaction between particle C and any other particle has been set up
Expand Down

0 comments on commit 8e49676

Please sign in to comment.