Skip to content

[DNM] Prototype using pablo to load pdb files #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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: 3 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ dependencies:
- pydata-sphinx-theme
- sphinx-jsonschema==1.15
- sphinx <7.1.2
# For pablo testing
- pyxdg
- pip:
- autodoc_pydantic<2.0.0
- git+https://github.com/openforcefield/[email protected]
21 changes: 13 additions & 8 deletions gufe/components/proteincomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from typing import Optional, Union

import numpy as np
import openff.toolkit.topology
import openmm.app
from openmm import app
from openmm import unit as omm_unit
from rdkit import Chem
Expand All @@ -19,6 +21,8 @@
from ..vendor.pdb_file.pdbfile import PDBFile
from ..vendor.pdb_file.pdbxfile import PDBxFile
from .explicitmoleculecomponent import ExplicitMoleculeComponent
from openff.pablo import CCD_RESIDUE_DEFINITION_CACHE, topology_from_pdb
from openff.units import unit

_BONDORDERS_OPENMM_TO_RDKIT = {
1: BondType.SINGLE,
Expand Down Expand Up @@ -120,8 +124,9 @@ def from_pdb_file(cls, pdb_file: str, name: str = ""):
ProteinComponent
the deserialized molecule
"""
openmm_PDBFile = PDBFile(pdb_file)
return cls._from_openmmPDBFile(openmm_PDBFile=openmm_PDBFile, name=name)
# openmm_PDBFile = PDBFile(pdb_file)
openfe_topology = topology_from_pdb(file=pdb_file, residue_database=CCD_RESIDUE_DEFINITION_CACHE, verbose_errors=True)
return cls._from_openff_topology(openff_topology=openfe_topology, name=name)

@classmethod
def from_pdbx_file(cls, pdbx_file: str, name=""):
Expand All @@ -144,12 +149,12 @@ def from_pdbx_file(cls, pdbx_file: str, name=""):
return cls._from_openmmPDBFile(openmm_PDBFile=openmm_PDBxFile, name=name)

@classmethod
def _from_openmmPDBFile(cls, openmm_PDBFile: Union[PDBFile, PDBxFile], name: str = ""):
def _from_openff_topology(cls, openff_topology: openff.toolkit.topology.Topology, name: str = ""):
"""Converts to our internal representation (rdkit Mol)

Parameters
----------
openmm_PDBFile : PDBFile or PDBxFile
openff_topology : openff.toolkit.topology.Topology
object of the protein
name : str
name of the protein
Expand All @@ -160,13 +165,13 @@ def _from_openmmPDBFile(cls, openmm_PDBFile: Union[PDBFile, PDBxFile], name: str
the deserialized molecule
"""
periodicTable = Chem.GetPeriodicTable()
mol_topology = openmm_PDBFile.getTopology()
openmm_topology = openff_topology.to_openmm()

rd_mol = Mol()
editable_rdmol = EditableMol(rd_mol)

# Add Atoms
for atom in mol_topology.atoms():
for atom in openmm_topology.atoms():
a = Atom(atom.element.atomic_number)

atom_monomerInfo = Chem.AtomPDBResidueInfo()
Expand All @@ -189,7 +194,7 @@ def _from_openmmPDBFile(cls, openmm_PDBFile: Union[PDBFile, PDBxFile], name: str
editable_rdmol.AddAtom(a)

# Add Bonds
for bond in mol_topology.bonds():
for bond in openmm_topology.bonds():
bond_order = _BONDORDERS_OPENMM_TO_RDKIT[bond.order]
editable_rdmol.AddBond(
beginAtomIdx=bond.atom1.index,
Expand All @@ -199,7 +204,7 @@ def _from_openmmPDBFile(cls, openmm_PDBFile: Union[PDBFile, PDBxFile], name: str

# Set Positions
rd_mol = editable_rdmol.GetMol()
positions = np.array(openmm_PDBFile.positions.value_in_unit(omm_unit.angstrom), ndmin=3)
positions = np.array(openff_topology.get_positions().to(unit.angstrom), ndmin=3)

for frame_id, frame in enumerate(positions):
conf = Conformer(frame_id)
Expand Down
Loading