Replace the pyMBE Pandas dataframe for a canonical pyMBE database#147
Replace the pyMBE Pandas dataframe for a canonical pyMBE database#147pm-blanco wants to merge 55 commits intopyMBE-dev:mainfrom
Conversation
| Notes: | ||
| - Values of the parameters are stored as PintQuantity objects for unit-aware calculations. | ||
| """ | ||
| pmb_type: Literal["bond"] = "bond" |
There was a problem hiding this comment.
Why do instances and templates have different level of protection for the argument pmb_type? i.e. Literal["bond"] = "bond" vs pmb_type: str = "bond". I think one can use same level of protection in all instances and templates for "pmb_type" argument
| pmb_type: Literal["bond"] = "bond" | ||
| name: str = Field(default="default") | ||
| bond_type: str # "HARMONIC", "FENE" | ||
| particle_name1: str | None = None |
There was a problem hiding this comment.
May be its a good idea to unify Optional[str] vs str | None used interchangeably with ParticleTemplate
| Unique non-negative integer identifying this molecule instance within the database. | ||
|
|
||
| assembly_id (int | None): | ||
| Identifier of the super-parent assembly (e.g. hydrogel) to which this residue belongs. ``None`` indicates that the residue is not assigned to any assembly. |
There was a problem hiding this comment.
The docstring for assembly_id should refer to a molecule and not to a residue.
| for _, tpl in self.db._templates["particle"].items(): | ||
| radius = (tpl.sigma.to_quantity(self.units) + tpl.offset.to_quantity(self.units))/2.0 | ||
| if dimensionless: | ||
| radius = radius.magnitude |
There was a problem hiding this comment.
It is ambiguous what magnitude does this line return. This will return the magnitude of the radius in the last unit Pint has stored in buffer memory which makes the behaviour of this method non-deterministic. I suggeted to change this line for radius = radius.m_as('reduced_length') and the variable name dimensionless for magnitude_reduced_length and fix the docs accordingly.
| if not used_ids: | ||
| return 0 | ||
| else: | ||
| if pmb_type not in self._instances or len(self._instances[pmb_type]) == 0: |
There was a problem hiding this comment.
len(self._instances[pmb_type]) == 0 Here second check might be redundant (delete instance already takes care of empty keys in ._instances)
return 0
| The state of the particle (e.g., protonation state, charge state). | ||
| coefficient (int): | ||
| Stoichiometric coefficient of the participant: | ||
| - ``coefficient < 0`` → reactant |
There was a problem hiding this comment.
"coefficient ∈ ℤ⁻ → reactant" or "coefficient ∈ {−1, −2, −3, …} → reactant"
| coefficient (int): | ||
| Stoichiometric coefficient of the participant: | ||
| - ``coefficient < 0`` → reactant | ||
| - ``coefficient > 0`` → product |
There was a problem hiding this comment.
"coefficient ∈ ℤ⁺ → product" or "coefficient ∈ {1, 2, 3, …} → product"
| Reaction equilibrium parameter (e.g., pKa, log K). The meaning | ||
| depends on ``reaction_type``. | ||
|
|
||
| reaction_type ('str'): |
| Must include at least two participants. | ||
|
|
||
| pK ('float'): | ||
| Reaction equilibrium parameter (e.g., pKa, log K). The meaning |
| """ | ||
| participants: List[ReactionParticipant] | ||
| pK: float | ||
| reaction_type: str |
| simulation_method: Optional[str] = None | ||
| name: Optional[str] = None | ||
|
|
||
| @validator("participants") |
There was a problem hiding this comment.
replace the variable ¨v¨ for ¨participants¨ in all the @validator("participants")
| particle_name (str): | ||
| The name of the particle template participating in the reaction. | ||
| state_name (str): | ||
| The state of the particle (e.g., protonation state, charge state). |
There was a problem hiding this comment.
The name of the particle state
| If the coefficient is zero. | ||
| """ | ||
| if coefficient == 0: | ||
| raise ValueError("Stoichiometric coefficient cannot be zero.") |
There was a problem hiding this comment.
If this line exists, is it still necessary the validator ¨def no_zero_coeff(cls, v)¨
| name: Optional[str] = None | ||
|
|
||
| @validator("participants") | ||
| def at_least_two_participants(cls, v): |
There was a problem hiding this comment.
Unify the cls/self nomenclature from this point onward.
| # Explicitly regenerate name after mutation | ||
| self.name = self._generate_name_from_participants() | ||
|
|
||
| def _generate_name_from_participants(self): |
There was a problem hiding this comment.
This method seems to be duplicated, see @root_validator def generate_name(cls, values):
Fixes #146, #123 and #18 :
Added
pmb.get_templates_df,pmb.get_instances_dfandpmb.get_reactions_df.pmb.save_databaseandpmb.load_database.pmb.define_particle_statesandpmb.define_monoprototic_particle_states.lib/handy_functionsto define residue and particle templates for aminoacids en peptides .and residues:define_protein_AA_particles,define_protein_AA_residuesanddefine_peptide_AA_residues.Changed
define_peptideanddefine_protein. Those definitions are now exposed to the user.Fixed
get_particle_id_map,calculate_HH,calculate_net_charge,center_object_in_simulation_boxnow support all template types in pyMBE, including hydrogels. Some of these methods have been renamed to expose directly in the API this change in behavior.Removed
add_bonds_to_espressohas been removed from the API. pyMBE now adds bonds internally to ESPResSo when molecule instances are created into ESPResSo.lattice_builder.ipynbhas been removed because its content is redundant with sample scriptbuild_hydrogel.py.Documentation
Tests