def __init__(self, smartspattern): """Initialise with a SMARTS pattern.""" self.search = chemaxon.sss.search.MolSearch() smarts = MolHandler(smartspattern) smarts.setQueryMode(True) smarts.aromatize() self.search.setQuery(smarts.molecule)
def desalt(mol): parmol = mol smi = mol.toFormat("smiles") parcount = 0 msmi = smi.split('.') for smi in msmi: mol = MolHandler(smi).getMolecule() count = mol.getAtomCount() if count > parcount: parcount = count parmol = mol return parmol
def readstring(format, string): """Read in a molecule from a string. Required parameters: format - Ignored, but needed for compatibility with other cinfony modules and also good for readability string Example: >>> input = "C1=CC=CS1" >>> mymol = readstring("smi", input) >>> len(mymol.atoms) 5 """ format = format.lower() if format not in informats: raise ValueError("%s is not a recognised JChem format" % format) try: mh = MolHandler(string) return Molecule(mh.molecule) except MolFormatException as ex: if sys.platform[:4] != "java": #Jpype exception ex = ex.message() raise IOError(ex) else: raise IOError("Problem reading the supplied string")
MolFormatException = chemaxon.formats.MolFormatException else: from jpype import * if not isJVMStarted(): _jvm = os.environ['JPYPE_JVM'] if _jvm[0] == '"': # Remove trailing quotes _jvm = _jvm[1:-1] _cp = os.pathsep.join( os.environ.get('CLASSPATH', '').split(os.pathsep)) startJVM(_jvm, "-Djava.class.path=" + _cp) chemaxon = JPackage("chemaxon") MolHandler = chemaxon.util.MolHandler try: _testmol = MolHandler() except TypeError: raise ImportError("jchem.jar file cannot be found.") # Exception wrappers for JPype MolExportException = JavaException MolFormatException = JavaException _descset = set(['HAcc', 'HDon', 'Heavy', 'LogD', 'LogP', 'Mass', 'TPSA']) _descset.update(dir(chemaxon.descriptors.scalars)) descs = [ cls for cls in _descset if hasattr(getattr(chemaxon.descriptors.scalars, cls), 'generate') and cls != 'LogD' ] + ['RotatableBondsCount'] """A list of supported descriptors"""
cfp.setBitCount(4) #output needs to look like this: #qSubs,qSmi,qID,inSmi,id,tversky #first read in queries q_split_input = open("frag_q_split_out", 'r') queries = [] for line in q_split_input: info = line.rstrip().split(",") #print info #generate fp for query #print info[2] mol = MolHandler(info[2]).getMolecule() mol.aromatize(Molecule.AROM_GENERAL) qfp = ChemicalFingerprint(cfp) qfp.generate(mol) qintfp = array.array('i', list(map(int, qfp.toFloatArray()))) queries.append((qintfp, info[0], info[1], info[2])) #print queries for line in sys.stdin: line_fields = re.split('\s|,', line) dbsmi = line_fields[0] dbid = line_fields[1]