Example #1
0
    def parseMolecule(self):
        '''
        turn the input into a toolkit molecule according to user settings

        indigo is supposed to read transparently, so we can do away with
        the format setting, basically. If it's numeric, we ask pubchem,
        if it isn't, we consider it a molecule.
        '''
        rawinput = self.data_string

        try:
            pubchemId = int(rawinput)
        except ValueError:
            pubchemId = None

        if pubchemId is not None:
            try:
                url = common.pubchem_url % pubchemId
                pubchemContent = urllib.urlopen(url).read()
            except IOError:
                raise common.MCFError, 'No connection to PubChem'

            self.data_string = pubchemContent

        #common.debug('rpc: %s' % self.rpc)
        #common.debug('data ---\n%s\n---' % self.data_string)

        try:
            tkmol = Indigo().loadMolecule(self.data_string)
        except IndigoException:
            raise common.MCFError, "Invalid input data"

        hydrogens = self.options['hydrogens']

        if hydrogens == 'add':
            tkmol.unfoldHydrogens()
            tkmol.layout()  # needed to give coordinates to added Hs

        elif hydrogens == 'delete':
            tkmol.foldHydrogens()

        if not tkmol.hasCoord() or self.options['recalculate_coordinates']:
            tkmol.layout()

        return tkmol
Example #2
0
    def parseMolecule(self):
        """
        turn the input into a toolkit molecule according to user settings

        indigo is supposed to read transparently, so we can do away with
        the format setting, basically. If it's numeric, we ask pubchem,
        if it isn't, we consider it a molecule.
        """
        rawinput = self.data_string

        try:
            pubchemId = int(rawinput)
        except ValueError:
            pubchemId = None

        if pubchemId is not None:
            try:
                url = common.pubchem_url % pubchemId
                pubchemContent = urllib.urlopen(url).read()
            except IOError:
                raise common.MCFError, "No connection to PubChem"

            self.data_string = pubchemContent

        # common.debug('rpc: %s' % self.rpc)
        # common.debug('data ---\n%s\n---' % self.data_string)

        try:
            tkmol = Indigo().loadMolecule(self.data_string)
        except IndigoException:
            raise common.MCFError, "Invalid input data"

        hydrogens = self.options["hydrogens"]

        if hydrogens == "add":
            tkmol.unfoldHydrogens()
            tkmol.layout()  # needed to give coordinates to added Hs

        elif hydrogens == "delete":
            tkmol.foldHydrogens()

        if not tkmol.hasCoord() or self.options["recalculate_coordinates"]:
            tkmol.layout()

        return tkmol