FragIt / fragit-main

FragIt main repository
Other
24 stars 12 forks source link

Make FragIt agnostic to underlying APIs #27

Open cstein opened 6 years ago

cstein commented 6 years ago

Currently we rely on OpenBabel to parse the SMARTS and give us the atoms of the corresponding fragments. We should also make an effort to support other APIs such as RDKit.

There is some code available in src/openbabelwrapper.py which could be used as a starting point.

I suppose something like which is easily testable depending only on the classes themselves.

class FragmentationBase(object):
    """ A virtual class with all the support the fragmentation class needs except smarts handling """
    pass

class OBFragmentation(FragmentationBase):
    """ Make openbabel specific implementation of Fragmentation class """
    pass

class RDKitFragmentation(FragmentationBase):
    """ Make RDKit specific implementation of Fragmentation class """
    pass

some logic would then be built-in depending on what packages are available. Some things that the classes should provide:

Initially we will ignore things like fragment grouping and so on.

cstein commented 6 years ago

Another option is to make the underlying molecule agnostic to the representation:

class MoleculeBase(object):
    def __init__(self, filename):
        self._filename = filename

    def getNumAtoms(self):
        raise NotImplemented

class OBMolecule(MoleculeBase):
    def __init__(self, filename):
        MoleculeBase.__init__(self, filename)
        self._mol = #load molecule with openbabel

    def getNumAtoms(self):
        return self._mol.GetNumAtoms()

class RDKitMolecule(MoleculeBase):
    pass

Using this approach, the fragmentation class will only interact with a molecule which exposes all the necessary features.