def mol_coords_to_numpy_array(mol): coords = OEFloatArray(mol.GetMaxAtomIdx() * 3) mol.GetCoords(coords) arr = np.ctypeslib.as_array(ctypes.cast(int(coords.PtrCast()), ctypes.POINTER(ctypes.c_float)), shape=(len(coords), )) return np.array(arr.reshape((-1, 3)))
def get_biomt(pdb): """ """ statement = text(""" SELECT assembly_serial, assembly_size, is_monomeric, pdb_chain_id, rotation, translation, is_at_identity FROM pdb_dev.biomt b JOIN pdb_dev.biomt_ops o USING(biomt_id) WHERE pdb = :pdb ORDER BY 1,3 """) # fetch data from pisa database result = engine.execute(statement, pdb=pdb.upper()).fetchall() biomt = {} is_monomeric = False # iterate through assemblies for (assembly_serial, assembly_size, is_monomeric), chain_iter in groupby(result, key=itemgetter(0, 1, 2)): biomt[assembly_serial] = {} # do not return pisa data for large assemblies / asu will be used instead if assembly_size > 26: app.log.warn( "one of the predicted assemblies contains {} chains - " "the asymmetric unit will be used instead.".format( assembly_size)) biomt = {} break # the complete ASU is monomeric and has to be split into individual chains if is_monomeric: break # iterate through chains for pdb_chain_id, operation_iter in groupby(chain_iter, key=itemgetter(3)): biomt[assembly_serial].update({str(pdb_chain_id): {}}) for operation_serial, operation in enumerate(operation_iter, 1): rotation, translation, is_at_identity = operation[4:] details = { 'rotation': OEFloatArray(rotation), 'translation': OEFloatArray(translation), 'is_at_identity': is_at_identity } biomt[assembly_serial][pdb_chain_id][ operation_serial] = details # debug assembly information try: app.log.debug("BIOMT contains {0} assembly/assemblies.".format( max(biomt.keys()))) # PDB entry does not have a REMARK 350 except ValueError: app.log.debug("NO REMARK 350 found.") return biomt, is_monomeric
def write_xyz(ofs, mol, coords): mol.SetCoords(OEFloatArray(coords.reshape(-1))) oechem.OEWriteMolecule(ofs, mol)
def __getMiscFile(self, ccPath, suppressHydrogens=False, importType="2D"): """Fetch a miscellaneous chemical file (ccPath) and build OE molecules for comparison and depiction. """ try: oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh) if oem.importFile(ccPath, type=importType): if self.__verbose: self.__lfh.write("+OEAlignDepilsct.__getMiscFile()\n") self.__lfh.write(" Title = %s\n" % oem.getTitle()) self.__lfh.write(" SMILES = %s\n" % oem.getCanSMILES()) self.__lfh.write(" SMILES (stereo) = %s\n" % oem.getIsoSMILES()) self.__lfh.write(" Formula (Hill) = %s\n" % oem.getFormula()) self.__lfh.write(" InChI key = %s\n" % oem.getInChIKey()) self.__lfh.write(" InChI = %s\n" % oem.getInChI()) else: self.__lfh.write( "+OEAlignDepict.__getMiscFile() Read failed for %s\n" % ccPath) return None, None, None # # oem.build2D() ccId = oem.getTitle() if suppressHydrogens: tMol = oem.getGraphMolSuppressH() else: tMol = oem.getMol() molXyzL = [] if importType == "3D": for ii, atm in enumerate(tMol.GetAtoms()): xyzL = OEFloatArray(3) tMol.GetCoords(atm, xyzL) molXyzL.append( (ii, atm.GetIdx(), atm.GetAtomicNum(), atm.GetName(), atm.GetType(), "%.3f" % xyzL[0], "%.3f" % xyzL[1], "%.3f" % xyzL[2])) fD = {} fD = { "Formula": oem.getFormula(), "SMILES": oem.getCanSMILES(), "SMILES_STEREO": oem.getIsoSMILES(), "InChI": oem.getInChI(), "InChIKey": oem.getInChIKey(), "xyz": molXyzL, } for ii, atm in enumerate(tMol.GetAtoms()): xyzL = OEFloatArray(3) tMol.GetCoords(atm, xyzL) if self.__verbose: self.__lfh.write( "OeAlignDepict.__getMiscFile - atom %d %s %s %s %s %r\n" % (ii, atm.GetIdx(), atm.GetAtomicNum(), atm.GetName(), atm.GetType(), xyzL)) return (ccId, tMol, fD) except: # noqa: E722 pylint: disable=bare-except traceback.print_exc(file=self.__lfh) # self.fail() return None, None, None
def importFile(self, filePath, type='2D'): # pylint: disable=redefined-builtin """ Contruct a OEGraphMol using the content of the input file. The input file must have a file extension recognized by the OE toolkit (e.g. .sdf) """ ifs = oemolistream() if not ifs.open(filePath): return False # # self.__oeMol = OEGraphMol() self.__oeMol = OEMol() OEReadMolecule(ifs, self.__oeMol) # OETriposAtomNames(self.__oeMol) if type == '2D': # run standard perceptions -- OEFindRingAtomsAndBonds(self.__oeMol) OEPerceiveChiral(self.__oeMol) for oeAt in self.__oeMol.GetAtoms(): st = oeAt.GetStringData("StereoInfo") if st == 'R': OESetCIPStereo(self.__oeMol, oeAt, OECIPAtomStereo_R) elif st == 'S': OESetCIPStereo(self.__oeMol, oeAt, OECIPAtomStereo_S) for oeBnd in self.__oeMol.GetBonds(): st = oeBnd.GetStringData("StereoInfo") if st == 'E': OESetCIPStereo(self.__oeMol, oeBnd, OECIPBondStereo_E) elif st == 'Z': OESetCIPStereo(self.__oeMol, oeBnd, OECIPBondStereo_Z) elif type == '3D': # run standard perceptions -- # self.__oeMol.SetDimension(3) OE3DToInternalStereo(self.__oeMol) OEFindRingAtomsAndBonds(self.__oeMol) # Other aromatic models: OEAroModelMDL or OEAroModelDaylight OEAssignAromaticFlags(self.__oeMol, OEAroModelOpenEye) self.updateCIPStereoOE() OEAddExplicitHydrogens(self.__oeMol) self.__molXyzL = [] aC = {} for ii, atm in enumerate(self.__oeMol.GetAtoms()): iAtNum = atm.GetAtomicNum() if iAtNum in aC: aC[iAtNum] += 1 else: aC[iAtNum] = 1 # Less than idea - should have an API atName = PdbxChemCompConstants._periodicTable[iAtNum - 1] + str( aC[iAtNum]) # pylint: disable=protected-access atm.SetName(atName) # xyzL = OEFloatArray(3) self.__oeMol.GetCoords(atm, xyzL) self.__molXyzL.append( (ii, atm.GetIdx(), atm.GetAtomicNum(), atm.GetName(), atm.GetType(), xyzL[0], xyzL[1], xyzL[2])) return True