def chemicalSimilarityOpenBabel(a,b): from cinfony import pybel #print a #print b mol1 = pybel.readstring("smi", a) mol2 = pybel.readstring("smi", b) return mol1.calcfp('maccs') | mol2.calcfp('maccs')
def read_fragment(self, name=None, fmt=None, handle=None, zero_to_origin=True): """Read a molecular structure from a file. Guess at the file type from extension if caller does not supply explicit fmt. If file handle is provided, read data from it. Otherwise open file name for reading. :param name: file to open :type name : str :param fmt: optional OpenBabel format code e.g. "xyz" :type fmt : str :param zero_to_origin: translate geometry to put atom 0 at origin :type zero_to_origin : bool :return: molecular fragment :rtype : Fragment """ if not fmt: try: fmt = name.rsplit(".", 1)[-1] except (IndexError, AttributeError): msg = "No fmt given for {0} and unable to guess from file extension".format(repr(name)) if handle is None: molecule = pybel.readfile(fmt, name).next() else: data = handle.read() molecule = pybel.readstring(fmt, data) fragment = Fragment(molecule) if zero_to_origin: fragment.set_zero_to_origin() return fragment
def write(self, fmt): """Write all fragments into a single molecular system, by way of an intermediate fused xyz. There might be a better way to do this, but it's not obvious. There may be strange results trying to write systems containing multiple fragments as a linear format like SMILES or InChI :param fmt: final format to write, e.g. "mopin" or "pdb" :type fmt : str """ natoms = len(self.atoms) xyzs = [] for f in self.fragments: #clip header and get right to the atom geometry xyz = f.write("xyz").strip().split("\n")[2:] xyzs.append("\n".join(xyz)) geoblock = "\n".join(xyzs) fused = "{0}\n\n{1}\n".format(natoms, geoblock) reread = pybel.readstring("xyz", fused) reread.title = self.title written = reread.write(fmt) return written
def getFingerprint(a): from cinfony import pybel #print a #print b mol1 = pybel.readstring("smi", a) return mol1.calcfp('maccs').bits
def make_fragment(self, representation, fmt="smiles"): """Take a linear representation of a molecule and add a title with IUPAC and SMILES designations. Convert a linear molecular specification to a 3D form. :param representation: linear molecule encoding :type representation : str :param fmt: smiles, inchi, etc. (default smiles) :type fmt : str :return: 3D-form molecular fragment :rtype: Fragment """ molecule = pybel.readstring(fmt, representation) molecule.make3D() fragment = Fragment(molecule) fragment.set_zero_to_origin() return fragment
def read_fragment(self, name=None, fmt=None, handle=None, zero_to_origin=True): """Read a molecular structure from a file. Guess at the file type from extension if caller does not supply explicit fmt. If file handle is provided, read data from it. Otherwise open file name for reading. :param name: file to open :type name : str :param fmt: optional OpenBabel format code e.g. "xyz" :type fmt : str :param zero_to_origin: translate geometry to put atom 0 at origin :type zero_to_origin : bool :return: molecular fragment :rtype : Fragment """ if not fmt: try: fmt = name.rsplit(".", 1)[-1] except (IndexError, AttributeError): msg = "No fmt given for {0} and unable to guess from file extension".format( repr(name)) if handle is None: molecule = pybel.readfile(fmt, name).next() else: data = handle.read() molecule = pybel.readstring(fmt, data) fragment = Fragment(molecule) if zero_to_origin: fragment.set_zero_to_origin() return fragment
#!/usr/bin/env python from subprocess import Popen, PIPE from cinfony import pybel import math, sys #smiles = raw_input("Enter the SMILES string for BBB permeability: ") smiles = str(sys.argv[1]) entry = "" try: # Reads the molecule into pybel pybelMol = pybel.readstring("smi", smiles); pybelFP = pybelMol.calcfp() pybelProperties = str(pybelFP).split(",") properties = pybelProperties properties = [p.strip() for p in properties] for current in properties: fixed = 0.0; # Take log_2(property) (May change later) if current != "0": fixed = math.log(float(current), 2) # Tack onto entry entry = entry + str(fixed) + " " command = "java Predictor " + entry p1 = Popen([command], stdout=PIPE, shell=True)