Skip to content

Commit

Permalink
28/5/24 starting on OpenBabelReader
Browse files Browse the repository at this point in the history
  • Loading branch information
lunamorrow committed May 28, 2024
1 parent 6016f68 commit 5590d9f
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions mda_openbabel_converter/OpenBabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,68 @@
import MDAnalysis as mda
from MDAnalysis.converters.base import ConverterBase
from MDAnalysis.coordinates.base import SingleFrameReaderBase
from MDAnalysis.core.groups import AtomGroup

try:
import openbabel as OB
from openbabel import OBMol
except ImportError:
print("Cannot find openbabel, install with 'pip install openbabel==2.4.0'")

class OpenBabelReader(SingleFrameReaderBase):
"""
Convert an OpenBabel OBMol (from the file) to a MDAnalysis AtomGroup
"""
@staticmethod
def _format_hint(thing):
"""
Base function to check if the reader can actually read this “thing”
(i.e., is it a file that can be converted to an OpenBabel OBMol?)
"""
pass
try:
import openbabel as OB
except ImportError:
return False
else:
return isinstance(thing, OB.OBMol)

def __init__(self, filename, **kwargs):
def __init__(self, filename: OBMol, **kwargs):
"""
Converts file to OBMol to AtomGroup
"""
self.atoms = []
self.n_atoms = 0
self.residues = []
self.n_residues = 0
self.segments = []
self.n_segments = 0

obmol = filename

# Atoms
names = []
chiralities = []
resnums = []
resnames = []
elements = []
masses = []
charges = []
aromatics = []
ids = []
atomtypes = []
segids = []
altlocs = []
chainids = []
icodes = []
occupancies = []
tempfactors = []

for i in range(1, obmol):
atom = obmol.GetAtomById(i-1)
# need to add handling incase attributes are invalid or null in OBMol
names.append(atom.GetType()) #char


pass

class OpenBabelConverter(ConverterBase):
Expand Down

0 comments on commit 5590d9f

Please sign in to comment.