Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions meeko/molsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ def _decode_object(cls, obj: dict[str, Any]):
int(k): [string_to_tuple(t) for t in v]
for k, v in obj["atom_to_ring_id"].items()
}
rdkit_molsetup.rmsd_symmetry_indices = list(map(string_to_tuple, obj["rmsd_symmetry_indices"]))
rdkit_molsetup.rmsd_symmetry_indices = tuple(map(string_to_tuple, obj["rmsd_symmetry_indices"]))
return rdkit_molsetup
# endregion

Expand Down Expand Up @@ -1641,7 +1641,6 @@ def from_mol(
# functions
molsetup = cls()
molsetup.mol = mol
molsetup.atom_true_count = molsetup.get_num_mol_atoms()
molsetup.name = molsetup.get_mol_name()
coords = rdkit_conformer.GetPositions()
molsetup.init_atom(compute_gasteiger_charges, read_charges_from_prop, coords)
Expand Down
36 changes: 26 additions & 10 deletions meeko/polymer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import numpy as np

data_path = files("meeko") / "data"
periodic_table = Chem.GetPeriodicTable()

try:
Expand Down Expand Up @@ -643,13 +642,18 @@ def add_dict(self, data, overwrite=False):
res_template = ResidueTemplate.from_dict(value)
self.residue_templates[key] = res_template
for link_label, value in data.get("padders", {}).items():
if overwrite or key not in self.padders:
padder = ResiduePadder.from_dict(data)
if overwrite or link_label not in self.padders:
padder = ResiduePadder.from_dict(value)
self.padders[link_label] = padder
return

@staticmethod
def _default_data_path():
return files("meeko") / "data"

@staticmethod
def lookup_filename(filename, data_path):
def lookup_filename(filename, data_path = None):
data_path = data_path or ResidueChemTemplates._default_data_path()
p = pathlib.Path(filename)
if not p.exists():
if (data_path / p).exists():
Expand All @@ -661,7 +665,8 @@ def lookup_filename(filename, data_path):
return filename

@classmethod
def from_json_file(cls, filename):
def from_json_file(cls, filename, data_path = None):
data_path = data_path or ResidueChemTemplates._default_data_path()
filename = cls.lookup_filename(filename, data_path)
with open(filename) as f:
jsonstr = f.read()
Expand All @@ -681,7 +686,8 @@ def from_json_file(cls, filename):
def create_from_defaults(cls):
return cls.from_json_file("residue_chem_templates")

def add_json_file(self, filename):
def add_json_file(self, filename, data_path = None):
data_path = data_path or ResidueChemTemplates._default_data_path()
filename = self.lookup_filename(filename, data_path)
with open(filename) as f:
jsonstr = f.read()
Expand Down Expand Up @@ -1052,6 +1058,12 @@ def _decode_object(cls, obj: dict[str, Any]):
k: Monomer.from_dict(v) for k, v in obj["monomers"].items()
}
polymer.log = obj["log"]
for nested_key in polymer.log:
if isinstance(polymer.log[nested_key], dict):
polymer.log[nested_key] = {
k: tuple(v) if isinstance(v, list) else v
for k, v in polymer.log[nested_key].items()
}

return polymer
# endregion
Expand Down Expand Up @@ -2425,7 +2437,7 @@ def __init__(

# (JSON-unbound) computed attributes
# TODO convert link indices/labels in template to rdkit_mol indices herein
# self.link_labels = {}
self.link_labels = {}
self.template = None

@staticmethod
Expand Down Expand Up @@ -2628,6 +2640,8 @@ class ResiduePadder(BaseJSONParsable):
----------
rxn : rdChemReactions.ChemicalReaction
Reaction SMARTS of a single-reactant, single-product reaction for padding.
adjacent_smarts : str
SMARTS pattern for identifying atoms in the adjacent residue to copy positions from.
adjacent_smartsmol : Chem.Mol
SMARTS molecule with mapping numbers to copy atom positions from part of adjacent residue.
adjacent_smartsmol_mapidx : list
Expand Down Expand Up @@ -2671,12 +2685,14 @@ def __init__(self, rxn_smarts: str, adjacent_res_smarts: str = None, auto_blunt:

# Fill in adjacent_smartsmol_mapidx
if adjacent_res_smarts is None:
self.adjacent_smarts = None
self.adjacent_smartsmol = None
self.adjacent_smartsmol_mapidx = None
return

# Ensure adjacent_res_smarts is None or a valid SMARTS
self.adjacent_smartsmol = self._initialize_adj_smartsmol(adjacent_res_smarts)
# Ensure adjacent_res_smarts is None or a valid SMARTS
self.adjacent_smarts = adjacent_res_smarts
self.adjacent_smartsmol = self._initialize_adj_smartsmol(self.adjacent_smarts)

# Ensure the mapping numbers are the same in adjacent_smartsmol and rxn_smarts's product
self._check_adj_smarts(self.rxn, self.adjacent_smartsmol)
Expand Down Expand Up @@ -2875,7 +2891,7 @@ def _check_target_mol(self, target_mol: Chem.Mol):
def json_encoder(cls, obj: "ResiduePadder") -> Optional[dict[str, Any]]:
output_dict = {
"rxn_smarts": rdChemReactions.ReactionToSmarts(obj.rxn),
"adjacent_res_smarts": serialize_optional(Chem.MolToSmarts, obj.adjacent_smartsmol),
"adjacent_res_smarts": obj.adjacent_smarts,
"auto_blunt": obj.auto_blunt,
}
# we are not serializing the adjacent_smartsmol_mapidx as that will
Expand Down
Loading