Skip to content

Commit 8abf3ee

Browse files
author
pmblanco
committed
fix general samples
1 parent 8ccef18 commit 8abf3ee

6 files changed

Lines changed: 109 additions & 50 deletions

File tree

pyMBE/lib/handy_functions.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ def define_peptide_AA_residues(sequence,model, pmb):
260260
261261
- Residue names are constructed as `"AA-<residue>"`, e.g., `"AA-A"`, `"AA-L"`.
262262
"""
263-
defined_residues = []
264263
for residue_name in sequence:
265264
if model == '1beadAA':
266265
central_bead = residue_name
@@ -273,11 +272,15 @@ def define_peptide_AA_residues(sequence,model, pmb):
273272
central_bead = 'CA'
274273
side_chains = [residue_name]
275274
residue_name='AA-'+residue_name
276-
if residue_name not in defined_residues:
275+
if "residue" in pmb.db._templates:
276+
if residue_name not in pmb.db._templates["residue"]:
277+
pmb.define_residue(name = residue_name,
278+
central_bead = central_bead,
279+
side_chains = side_chains)
280+
else:
277281
pmb.define_residue(name = residue_name,
278-
central_bead = central_bead,
279-
side_chains = side_chains)
280-
defined_residues.append(residue_name)
282+
central_bead = central_bead,
283+
side_chains = side_chains)
281284

282285
def do_reaction(algorithm, steps):
283286
"""

samples/branched_polyampholyte.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,10 @@
162162
anion_name=anion_name,
163163
c_salt=c_salt)
164164

165-
#List of ionisable groups
166-
# collect ionisable particles*
167-
acidbase_particles = ["A","B"]
165+
# count acid/base particles
166+
pka_set = pmb.get_pka_set()
168167
acid_base_ids = []
169-
for name in acidbase_particles:
168+
for name in pka_set.keys():
170169
acid_base_ids+=pmb.db.find_instance_ids_by_name(pmb_type="particle",
171170
name=name)
172171
total_ionisable_groups = len(acid_base_ids)

samples/peptide_cpH.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
pmb = pyMBE.pymbe_library(seed=42)
3030

3131
# Load some functions from the handy_scripts library for convenience
32-
from pyMBE.lib.handy_functions import setup_electrostatic_interactions
33-
from pyMBE.lib.handy_functions import relax_espresso_system
34-
from pyMBE.lib.handy_functions import setup_langevin_dynamics
35-
from pyMBE.lib.handy_functions import do_reaction
32+
from pyMBE.lib.handy_functions import setup_electrostatic_interactions, relax_espresso_system, setup_langevin_dynamics, do_reaction, define_peptide_AA_residues
3633
from pyMBE.lib.analysis import built_output_name
3734

3835
parser = argparse.ArgumentParser(description='Sample script to run the pre-made peptide models with pyMBE')
@@ -97,7 +94,13 @@
9794
path_to_interactions=pmb.root / "parameters" / "peptides" / "Lunkad2021"
9895
path_to_pka=pmb.root / "parameters" / "pka_sets" / "Hass2015.json"
9996
pmb.load_database(folder=path_to_interactions)
100-
pmb.load_pka_set (path_to_pka)
97+
pmb.load_pka_set(path_to_pka)
98+
99+
# Define acid/base particle states
100+
pka_set = pmb.get_pka_set()
101+
for particle_name in pka_set.keys():
102+
pmb.define_monoprototic_particle_states(particle_name=particle_name,
103+
acidity=pka_set[particle_name]["acidity"])
101104

102105
generic_bond_length=0.4 * pmb.units.nm
103106
generic_harmonic_constant = 400 * pmb.units('reduced_energy / reduced_length**2')
@@ -110,8 +113,11 @@
110113
bond_parameters = HARMONIC_parameters)
111114

112115

113-
# Defines the peptide in the pyMBE data frame
116+
# Defines the peptide in the pyMBE database
114117
peptide_name = 'generic_peptide'
118+
define_peptide_AA_residues(sequence=sequence,
119+
model="2beadAA",
120+
pmb=pmb)
115121
pmb.define_peptide (name=peptide_name,
116122
sequence=sequence,
117123
model=model)
@@ -125,6 +131,8 @@
125131
sigma=0.35*pmb.units.nm,
126132
epsilon=1*pmb.units('reduced_energy'))
127133

134+
135+
128136
# Create an instance of an espresso system
129137
espresso_system=espressomd.System (box_l = [L.to('reduced_length').magnitude]*3)
130138
espresso_system.time_step=dt
@@ -152,20 +160,28 @@
152160
vtf.writevsf(espresso_system, coordinates)
153161
vtf.writevcf(espresso_system, coordinates)
154162

155-
#List of ionisable groups
156-
basic_groups = pmb.df.loc[(~pmb.df['particle_id'].isna()) & (pmb.df['acidity']=='basic')].name.to_list()
157-
acidic_groups = pmb.df.loc[(~pmb.df['particle_id'].isna()) & (pmb.df['acidity']=='acidic')].name.to_list()
158-
list_ionisable_groups = basic_groups + acidic_groups
159-
total_ionisable_groups = len(list_ionisable_groups)
163+
# count acid/base particles
164+
pka_set = pmb.get_pka_set()
165+
acid_base_ids = []
166+
list_ionisable_groups = []
167+
for name in pka_set.keys():
168+
part_ids = pmb.db.find_instance_ids_by_name(pmb_type="particle",
169+
name=name)
170+
if part_ids:
171+
acid_base_ids+=part_ids
172+
list_ionisable_groups+=[name]
173+
total_ionisable_groups = len(acid_base_ids)
160174

161175
if verbose:
162176
print(f"The box length of your system is {L.to('reduced_length')} {L.to('nm')}")
163177
print(f"The peptide concentration in your system is {calculated_peptide_concentration.to('mol/L')} with {N_peptide_chains} peptides")
164178
print(f"The ionisable groups in your peptide are {list_ionisable_groups}")
165179

166-
cpH, labels = pmb.setup_cpH(counter_ion=cation_name, constant_pH=pH_value)
180+
cpH = pmb.setup_cpH(counter_ion=cation_name,
181+
constant_pH=pH_value)
167182
if verbose:
168-
print(f"The acid-base reaction has been successfully setup for {labels}")
183+
print("The acid-base reaction has been successfully set up for:")
184+
print(pmb.get_reactions_df())
169185

170186
# Setup espresso to track the ionization of the acid/basic groups in peptide
171187
type_map =pmb.get_type_map()

samples/peptide_mixture_grxmc_ideal.py

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from espressomd.io.writer import vtf
2525
import pyMBE
2626
from pyMBE.lib.analysis import built_output_name
27-
from pyMBE.lib.handy_functions import do_reaction
27+
from pyMBE.lib.handy_functions import do_reaction, define_peptide_AA_residues
2828

2929
# Create an instance of pyMBE library
3030
pmb = pyMBE.pymbe_library(seed=42)
@@ -95,11 +95,27 @@
9595
# Note that this parameterization only includes some of the natural aminoacids
9696
# For the other aminoacids the user needs to use a parametrization including all the aminoacids in the peptide sequence
9797
path_to_pka=pmb.root / "parameters" / "pka_sets" / "Hass2015.json"
98-
path_to_interactions=pmb.root / "parameters" / "peptides" / "Lunkad2021.json"
99-
100-
pmb.load_interaction_parameters(filename=path_to_interactions)
98+
path_to_interactions=pmb.root / "parameters" / "peptides" / "Lunkad2021"
99+
100+
pmb.load_database(folder=path_to_interactions)
101+
# define templates for the c and n ends
102+
pmb.define_particle(name="n",
103+
sigma=1*pmb.units.reduced_length,
104+
epsilon=1*pmb.units.reduced_energy,
105+
acidity="basic")
106+
pmb.define_particle(name="c",
107+
sigma=1*pmb.units.reduced_length,
108+
epsilon=1*pmb.units.reduced_energy,
109+
acidity="acidic")
101110
pmb.load_pka_set(path_to_pka)
102111

112+
# Define acid/base particle states
113+
pka_set = pmb.get_pka_set()
114+
for particle_name in pka_set.keys():
115+
if particle_name not in ["c", "n"]: # Avoid redefing the ends
116+
pmb.define_monoprototic_particle_states(particle_name=particle_name,
117+
acidity=pka_set[particle_name]["acidity"])
118+
103119
# Defines the bonds
104120
bond_type = 'harmonic'
105121
generic_bond_length=0.4 * pmb.units.nm
@@ -120,6 +136,12 @@
120136
pmb.define_peptide (name=peptide2,
121137
sequence=sequence2,
122138
model=model)
139+
define_peptide_AA_residues(sequence=sequence1,
140+
model=model,
141+
pmb=pmb)
142+
define_peptide_AA_residues(sequence=sequence2,
143+
model=model,
144+
pmb=pmb)
123145

124146
# Solution parameters
125147
c_salt=5e-3 * pmb.units.mol/ pmb.units.L
@@ -212,31 +234,35 @@
212234
vtf.writevsf(espresso_system, coordinates)
213235
vtf.writevcf(espresso_system, coordinates)
214236

215-
#List of ionisable groups
216-
basic_groups = pmb.df.loc[(~pmb.df['particle_id'].isna()) & (pmb.df['acidity']=='basic')].name.to_list()
217-
acidic_groups = pmb.df.loc[(~pmb.df['particle_id'].isna()) & (pmb.df['acidity']=='acidic')].name.to_list()
218-
list_ionisable_groups = basic_groups + acidic_groups
219-
total_ionisable_groups = len (list_ionisable_groups)
237+
# count acid/base particles
238+
pka_set = pmb.get_pka_set()
239+
acid_base_ids = []
240+
for name in pka_set.keys():
241+
acid_base_ids+=pmb.db.find_instance_ids_by_name(pmb_type="particle",
242+
name=name)
243+
total_ionisable_groups = len(acid_base_ids)
244+
220245
# Get peptide net charge
221246
if verbose:
222247
print("The box length of your system is", L.to('reduced_length'), L.to('nm'))
223248

224249
if args.mode == 'standard':
225-
grxmc, sucessful_reactions_labels, ionic_strength_res = pmb.setup_grxmc_reactions(pH_res=pH_value,
226-
c_salt_res=c_salt,
227-
proton_name=proton_name,
228-
hydroxide_name=hydroxide_name,
229-
salt_cation_name=sodium_name,
230-
salt_anion_name=chloride_name,
231-
activity_coefficient=lambda x: 1.0)
250+
grxmc, ionic_strength_res = pmb.setup_grxmc_reactions(pH_res=pH_value,
251+
c_salt_res=c_salt,
252+
proton_name=proton_name,
253+
hydroxide_name=hydroxide_name,
254+
salt_cation_name=sodium_name,
255+
salt_anion_name=chloride_name,
256+
activity_coefficient=lambda x: 1.0)
232257
elif args.mode == 'unified':
233-
grxmc, sucessful_reactions_labels, ionic_strength_res = pmb.setup_grxmc_unified(pH_res=pH_value,
234-
c_salt_res=c_salt,
235-
cation_name=cation_name,
236-
anion_name=anion_name,
237-
activity_coefficient=lambda x: 1.0)
258+
grxmc, ionic_strength_res = pmb.setup_grxmc_unified(pH_res=pH_value,
259+
c_salt_res=c_salt,
260+
cation_name=cation_name,
261+
anion_name=anion_name,
262+
activity_coefficient=lambda x: 1.0)
238263
if verbose:
239-
print('The acid-base reaction has been sucessfully setup for ', sucessful_reactions_labels)
264+
print("The acid-base reaction has been successfully set up for:")
265+
print(pmb.get_reactions_df())
240266

241267
# Setup espresso to track the ionization of the acid/basic groups in peptide
242268
type_map =pmb.get_type_map()

samples/plot_peptide_cpH.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import argparse
2424
import pathlib
2525
import pandas as pd
26+
import pyMBE.lib.handy_functions as hf
2627
# Create an instance of pyMBE library
2728
import pyMBE
2829
pmb = pyMBE.pymbe_library(seed=42)
@@ -52,15 +53,18 @@
5253

5354
# Define peptide parameters
5455
sequence = args.sequence
55-
# Define the peptide in the pyMBE dataframe and load the pka set
56+
# Define the peptide in the pyMBE database and load the pka set
5657
# This is necessary to calculate the analytical solution from the Henderson-Hasselbach equation
5758
peptide = 'generic_peptide'
58-
pmb.define_peptide (name=peptide,
59-
sequence=sequence,
60-
model="1beadAA") # not really relevant for plotting
59+
model="1beadAA" # not really relevant for plotting
60+
pmb.define_peptide(name=peptide,
61+
sequence=sequence,
62+
model=model)
6163
path_to_pka=pmb.root / "parameters" / "pka_sets" / "Hass2015.json"
6264
pmb.load_pka_set(path_to_pka)
63-
65+
hf.define_peptide_AA_residues(sequence=sequence,
66+
model=model,
67+
pmb=pmb)
6468
# Calculate the ideal titration curve of the peptide with Henderson-Hasselbach equation
6569
if args.mode == "plot":
6670
pH_range_HH = np.linspace(2, 12, num=100)

samples/plot_peptide_mixture_grxmc_ideal.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2024 pyMBE-dev team
2+
# Copyright (C) 2024-2026 pyMBE-dev team
33
#
44
# This file is part of pyMBE.
55
#
@@ -22,6 +22,7 @@
2222
import pandas as pd
2323
import argparse
2424
import pathlib
25+
from pyMBE.lib.handy_functions import define_peptide_AA_residues
2526

2627
parser = argparse.ArgumentParser(description='Plots the titration data from peptide.py and the corresponding analytical solution.')
2728
parser.add_argument('--sequence1',
@@ -65,6 +66,8 @@
6566
# Create an instance of pyMBE library
6667
pmb = pyMBE.pymbe_library(seed=42)
6768
c_salt=args.csalt * pmb.units.mol/ pmb.units.L
69+
model = "1beadAA"
70+
6871

6972
# Define peptide parameters
7073
sequence1 = args.sequence1
@@ -75,6 +78,13 @@
7578

7679
# Define the peptides in the pyMBE data frame and load the pka set
7780
# This is necesary to calculate the analytical solution from the Henderson-Hasselbach equation
81+
82+
define_peptide_AA_residues(sequence=sequence1,
83+
model=model,
84+
pmb=pmb)
85+
define_peptide_AA_residues(sequence=sequence2,
86+
model=model,
87+
pmb=pmb)
7888
peptide1 = 'generic_peptide1'
7989
pmb.define_peptide (name=peptide1,
8090
sequence=sequence1,
@@ -86,6 +96,7 @@
8696
path_to_pka=pmb.root / "parameters" / "pka_sets" / "Hass2015.json"
8797
pmb.load_pka_set(path_to_pka)
8898

99+
89100
# Calculate the ideal titration curve of the peptide with Henderson-Hasselbach equation
90101
if args.mode == "plot":
91102
pH_range_HH = np.linspace(2, 12, num=100)

0 commit comments

Comments
 (0)