Skip to content

Commit

Permalink
added value error if pka not provided for acidic or basic particles (#24
Browse files Browse the repository at this point in the history
)

* added value error if pka not provided for acidic or basic particles

* remove acidity from peptide parameters, add marius as contributor, improve value error messages

* added acidity test

* adjusted the parameter files to not having acidity

* removed all acididty in params

* changed diameter to sigma

* Add aditional unit tests, remove tests from samples instruction in Makefile

* Add missing test to the CI

---------

Co-authored-by: blancoapa <[email protected]>
Co-authored-by: Pablo M. Blanco <[email protected]>
  • Loading branch information
3 people authored Apr 22, 2024
1 parent 55b78a2 commit 246f569
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 25 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ docs:

tests:
python3 testsuite/lj_tests.py
python3 testsuite/set_particle_acidity_test.py
python3 testsuite/generate_perpendicular_vectors_test.py
python3 testsuite/create_molecule_position_test.py
python3 testsuite/read-write-df_test.py
Expand All @@ -17,6 +18,9 @@ tests:
python3 testsuite/grxmc_ideal_tests.py
python3 testsuite/peptide_tests.py
python3 testsuite/weak_polyelectrolyte_dialysis_test.py
sample:
python3 sample_scripts/peptide_simulation_example.py


visual:
python3 handy_scripts/vmd-traj.py
Expand Down
14 changes: 7 additions & 7 deletions parameters/peptides/Avogadro_parametrization.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Parameters from Lunkad, R. et al. Molecular Systems Design & Engineering (2021), 6(2), 122-131.
{"object_type":"particle", "name": "CA", "q":0, "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "A", "q":0, "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "c", "acidity": "acidic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "D", "acidity": "acidic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "E", "acidity": "acidic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "Y", "acidity": "acidic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "n", "acidity": "basic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "H", "acidity": "basic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "K", "acidity": "basic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "c", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "D", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "E", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "Y", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "n", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "H", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "K", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"bond", "name1": "CA", "name2": "CA", "bond_type": "harmonic", "r_0": {"value":0.382, "units":"nm"}, "k": {"value": 400, "units":"reduced_energy / nm**2"}}
{"object_type":"bond", "name1": "CA", "name2": "A", "bond_type": "harmonic", "r_0": {"value":0.153, "units":"nm"}, "k": {"value": 400, "units":"reduced_energy / nm**2"}}
{"object_type":"bond", "name1": "CA", "name2": "c", "bond_type": "harmonic", "r_0": {"value":0.246, "units":"nm"}, "k": {"value": 400, "units":"reduced_energy / nm**2"}}
Expand Down
24 changes: 12 additions & 12 deletions parameters/peptides/Blanco2020.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Parameters from Blanco et al. Soft Matter, 17(3), 655-669, 2021.
{"object_type":"particle", "name": "D", "acidity": "acidic", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "E", "acidity": "acidic", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "n", "acidity": "basic", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "S", "q":0, "acidity": "inert", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "H", "acidity": "basic", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "A", "q":0,"acidity": "inert", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "K", "acidity": "basic", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "Y", "acidity": "acidic", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "R", "acidity": "basic", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "G", "q":0,"acidity": "inert", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "F", "q":0,"acidity": "inert", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "c", "acidity": "acidic", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "D", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "E", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "n", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "S", "q":0, "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "H", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "A", "q":0, "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "K", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "Y", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "R", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "G", "q":0, "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "F", "q":0, "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "c", "sigma": {"value":0.4, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"bond", "name1": "n", "name2": "D", "bond_type": "harmonic", "r_0": {"value":0.4, "units":"nm"}, "k": {"value": 0.41, "units":"N / m"}}
{"object_type":"bond", "name1": "S", "name2": "D", "bond_type": "harmonic", "r_0": {"value":0.4, "units":"nm"}, "k": {"value": 0.41, "units":"N / m"}}
{"object_type":"bond", "name1": "S", "name2": "H", "bond_type": "harmonic", "r_0": {"value":0.4, "units":"nm"}, "k": {"value": 0.41, "units":"N / m"}}
Expand Down
10 changes: 5 additions & 5 deletions parameters/peptides/Lunkad2021.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Parameters from Lunkad, R. et al. Molecular Systems Design & Engineering (2021), 6(2), 122-131.
{"object_type":"particle", "name": "CA", "q":0, "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "D", "acidity": "acidic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "E", "acidity": "acidic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "H", "acidity": "basic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "Y", "acidity": "acidic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "K", "acidity": "basic", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "D", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "E", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "H", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "Y", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"particle", "name": "K", "sigma": {"value":0.35, "units":"nm"}, "epsilon":{"value":1, "units":"reduced_energy"}}
{"object_type":"bond", "name1": "CA", "name2": "CA", "bond_type": "harmonic", "r_0": {"value":0.382, "units":"nm"}, "k": {"value": 400, "units":"reduced_energy / nm**2"}}
{"object_type":"bond", "name1": "CA", "name2": "D", "bond_type": "harmonic", "r_0": {"value":0.329, "units":"nm"}, "k": {"value": 400, "units":"reduced_energy / nm**2"}}
{"object_type":"bond", "name1": "CA", "name2": "E", "bond_type": "harmonic", "r_0": {"value":0.435, "units":"nm"}, "k": {"value": 400, "units":"reduced_energy / nm**2"}}
Expand Down
4 changes: 3 additions & 1 deletion pyMBE.py
Original file line number Diff line number Diff line change
Expand Up @@ -2339,7 +2339,9 @@ def set_particle_acidity(self, name, acidity='inert', default_charge=0, pka=None
"""
acidity_valid_keys = ['inert','acidic', 'basic']
if acidity not in acidity_valid_keys:
raise ValueError(self.df[name].name +' provided acidity not supported, valid keys are ', acidity_valid_keys)
raise ValueError(f"Acidity {acidity} provided for particle name {name} is not supproted. Valid keys are: {acidity_valid_keys}")
if acidity in ['acidic', 'basic'] and pka is None:
raise ValueError(f"pKa not provided for particle with name {name} with acidity {acidity}. pKa must be provided for acidic or basic particles.")
for index in self.df[self.df['name']==name].index:
if pka:
self.add_value_to_df(key=('pka',''),index=index,new_value=pka)
Expand Down
94 changes: 94 additions & 0 deletions testsuite/set_particle_acidity_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Import pyMBE and other libraries
import numpy as np
import pyMBE

# Create an instance of pyMBE library
pmb = pyMBE.pymbe_library()

def check_acid_base_setup(input_parameters,acidity_setup):
"""
Checks if pyMBE stores in the pmb.df the input parameters for acid/base particles correctly.
Args:
input_parameters(`dict`): dictionary with the input parameters for define_particle.
acidity_setup(`dict`): dictionary with the expected setup that pyMBE should do in the pmb.df foor acid/base particles.
"""
pmb.define_particle(**input_parameters)
if input_parameters["acidity"] == "inert":
input_parameters.pop("q")
# Checks that the input parameters are stored properly
for parameter_key in input_parameters.keys():
np.testing.assert_equal(actual=pmb.df[parameter_key].values[0],
desired=input_parameters[parameter_key],
verbose=True)
# Checks that the setup of the acid base properties is done correctly
for state in ["state_one","state_two"]:
for state_atribute in ["label","charge"]:
np.testing.assert_equal(actual=pmb.df[state][state_atribute].values[0],
desired=acidity_setup[state][state_atribute],
verbose=True)
# checks that pyMBE assigns different espresso type to each state
np.testing.assert_raises(AssertionError, np.testing.assert_equal, pmb.df["state_one"]["es_type"].values[0], pmb.df["state_two"]["es_type"].values[0])


print("*** Particle acidity unit tests ***")
print(f"*** Unit test: check that all acid/base input parameters in define_particle for an inert particle are correctly stored in pmb.df***")
# Clean pmb.df
pmb.setup_df()
input_parameters={"name":"I",
"acidity": "inert",
"pka": np.nan,
"q":2}
acidity_setup={"state_one":{"label":f"{input_parameters['name']}",
"charge":2},
"state_two":{"label": np.nan,
"charge":np.nan},}

check_acid_base_setup(input_parameters=input_parameters,
acidity_setup=acidity_setup)

print(f"*** Unit test passed ***")
print(f"*** Unit test: check that all acid/base input parameters in define_particle for an acid are correctly stored in pmb.df***")
# Clean pmb.df
pmb.setup_df()
input_parameters={"name":"A",
"acidity": "acidic",
"pka":4}
acidity_setup={"state_one":{"label":f"{input_parameters['name']}H",
"charge":0},
"state_two":{"label":f"{input_parameters['name']}",
"charge":-1},}

check_acid_base_setup(input_parameters=input_parameters,
acidity_setup=acidity_setup)
print(f"*** Unit test passed ***")
print(f"*** Unit test: check that all acid/base input parameters in define_particle for a base are correctly stored in pmb.df***")
# Clean pmb.df
pmb.setup_df()
input_parameters={"name":"B",
"acidity": "basic",
"pka":9}
acidity_setup={"state_one":{"label":f"{input_parameters['name']}H",
"charge":1},
"state_two":{"label":f"{input_parameters['name']}",
"charge":0},}

check_acid_base_setup(input_parameters=input_parameters,
acidity_setup=acidity_setup)
print(f"*** Unit test passed ***")
print(f"*** Unit test: check that set_particle_acidity raises a ValueError if pKa is not provided and pKa is acidic or basic ***")
input_parametersA={"name":"A",
"acidity": "acidic" }

input_parametersB= {"name": "B",
"acidity": "basic"}
np.testing.assert_raises(ValueError, pmb.set_particle_acidity,**input_parametersA)
np.testing.assert_raises(ValueError, pmb.set_particle_acidity, **input_parametersB)
print(f"*** Unit test passed ***")
print(f"*** Unit test: check that set_particle_acidity raises a ValueError if a non-supported acidity is provided ***")
input_parametersA={"name":"A",
"acidity": "random" }
np.testing.assert_raises(ValueError, pmb.set_particle_acidity,**input_parametersA)
print(f"*** Unit test passed ***")
print(f"*** All unit tests passed ***")

0 comments on commit 246f569

Please sign in to comment.