Skip to content

Commit

Permalink
Merge pull request #1 from Yoshanuikabundi/abandon-aa-variants
Browse files Browse the repository at this point in the history
Abandon aa variants
  • Loading branch information
Yoshanuikabundi authored Jan 9, 2025
2 parents 06492e9 + f2cfb00 commit cbe3352
Show file tree
Hide file tree
Showing 9 changed files with 1,496 additions and 603 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,5 @@ poetry.lock

# ruff
.ruff_cache

.ccd_cache
940 changes: 862 additions & 78 deletions examples/load_pdb.ipynb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions openff/pablo/_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _load_unknown_residue(


def topology_from_pdb(
path: PathLike[str],
path: PathLike[str] | str,
unknown_molecules: Iterable[Molecule] = [],
residue_database: Mapping[
str,
Expand Down Expand Up @@ -284,7 +284,8 @@ def topology_from_pdb(

prev_chain_id = data.chain_id[prototype_index]
prev_model = data.model[prototype_index]
molecules.append(this_molecule)
if this_molecule.n_atoms != 0:
molecules.append(this_molecule)

for offmol in molecules:
offmol._invalidate_cached_properties()
Expand Down
62 changes: 62 additions & 0 deletions openff/pablo/_tests/test_pdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import pytest
from openff.toolkit import Molecule, Topology
from pkg_resources import resource_filename

from openff.pablo._pdb import topology_from_pdb
from openff.pablo._utils import sort_tuple


@pytest.mark.parametrize(
("pdbfile", "unknown_smiles"),
[
(
"data/5ap1_prepared.pdb",
["O=C([O-])Cn1cc(cn1)c2ccc(cc2OCC#N)Nc3ccc(c(n3)NC4CCCCC4)C#N"],
),
],
)
def test_connectivity_and_atom_order_and_net_residue_charge_and_metadata_matches_legacy(
pdbfile: str,
unknown_smiles: list[str],
):
unknown_molecules = [Molecule.from_smiles(s) for s in unknown_smiles]
filename = resource_filename(__name__, pdbfile)

pablo_top = topology_from_pdb(
filename,
unknown_molecules=unknown_molecules,
)
legacy_top: Topology = Topology.from_pdb(
filename,
unique_molecules=unknown_molecules,
)

assert pablo_top.n_molecules == legacy_top.n_molecules
for pablo_mol, legacy_mol in zip(pablo_top.molecules, legacy_top.molecules):
assert pablo_mol.n_atoms == legacy_mol.n_atoms
for pablo_atom, legacy_atom in zip(pablo_mol.atoms, legacy_mol.atoms):
assert pablo_atom.name == legacy_atom.name
assert pablo_atom.symbol == legacy_atom.symbol
for key in [
"residue_name",
"chain_id",
"residue_number",
"insertion_code",
]:
assert pablo_atom.metadata[key] == legacy_atom.metadata[key]

pablo_bonds = {
sort_tuple((bond.atom1_index, bond.atom2_index)) for bond in pablo_mol.bonds
}
legacy_bonds = {
sort_tuple((bond.atom1_index, bond.atom2_index))
for bond in legacy_mol.bonds
}
assert pablo_bonds == legacy_bonds

for pablo_res, legacy_res in zip(pablo_top.residues, legacy_top.residues):
pablo_res_charge, legacy_res_charge = 0, 0
for pablo_atom, legacy_atom in zip(pablo_res.atoms, legacy_res.atoms):
pablo_res_charge += pablo_atom.formal_charge
legacy_res_charge += legacy_atom.formal_charge
assert pablo_res_charge == legacy_res_charge
Loading

0 comments on commit cbe3352

Please sign in to comment.