def get_pdbs_to_process(args): """ Returns a list containing the PDB codes of PDB entries that should be processed. """ pdbs = [] # process all PDB files on mirror if args.all: pass # process only specific pdb entries elif args.structures: pdbs = [pdb.lower() for pdb in args.structures.strip().split(',') if pdb] # use only a limited subset of the pdb elif args.testset: pdbs = map(string.lower, app.config['test sets'][args.testset]) # apply an offset to the list of PDBs by using the given offset PDB as index if pdbs and args.offset: try: index = pdbs.index(args.offset.lower()) pdbs = pdbs[index:] except ValueError: app.log.fatal("cannot apply offset: {0} is not in list of PDBs to " "process.".format(args.offset)) app.close() sys.exit(1) return sorted(pdbs)
def dump(args, tablenames=None): """ """ # complete schema if not tablenames: app.log.debug("dumping metadata of all tables in the CREDO schema.") for table in metadata.tables.values(): print CreateTable(table, on='postgresql', bind=metadata.bind) for index in table.indexes: print CreateIndex(index, on='postgresql', bind=metadata.bind) # only specific tables else: # check if the given tables are are defined in CREDO for tablename in tablenames: if tablename not in metadata.tables: app.log.fatal( "table {0} is not defined in CREDO".format(tablename)) app.close() else: table = metadata.tables[tablename] print CreateTable(table, on='postgresql', bind=metadata.bind) for index in table.indexes: print CreateIndex(index, on='postgresql', bind=metadata.bind)
def create(args, tablenames=None): """ """ if not tablenames: if args.raw or args.core: for table in metadata.tables.values(): # only create the 'raw' tables used for loading data if args.raw and table.name.startswith('raw'): if not args.missing: app.log.debug("Dropping tables") #table.drop(checkfirst=args.checkfirst) table.create(checkfirst=args.checkfirst) # core tables elif args.core and table.name.startswith('raw'): app.log.debug("Dropping tables") #metadata.remove(table) if args.core: if not args.missing: app.log.debug("Dropping tables") #metadata.drop_all(checkfirst=args.checkfirst) metadata.create_all(checkfirst=args.checkfirst) # create all tables else: if args.sure: app.log.info( "creating all elements defined in the current schema!") if not args.missing: app.log.debug("Dropping tables") #metadata.drop_all(checkfirst=args.checkfirst) metadata.create_all(checkfirst=args.checkfirst) else: app.log.error( "you must specify the --sure option before attempting " "to drop and create the whole schema.") app.close() else: for tablename in tablenames: if tablename in metadata.tables: table = metadata.tables[tablename] if not args.missing: table.drop(checkfirst=args.checkfirst) table.create(checkfirst=args.checkfirst) else: #current_names = metadata.tables.keys() app.log.warn( "cannot create table {0}: not defined in the current schema." .format(tablename))
def main(): """ Dispatch the commands from here. """ # run the application app.run() # get the controller that was specified on the command line controller = app.controller # this script was called without any controller argument if not controller: pass # interact with the current configuration elif controller.Meta.label == 'base': base.do(controller) # work with the CREDO schema elif controller.Meta.label == 'db': from credovi.run import db db.do(controller) elif controller.Meta.label == 'credo': # generate interaction data if controller.command == 'contacts': credo.do(controller) elif controller.command == 'preparepdb': preparepdb.do(controller) elif controller.Meta.label == 'mmcif': mmcif.do(controller) # run stand-alone version elif controller.Meta.label == 'credosa': credosa.do(controller) # run stand-alone version elif controller.Meta.label == 'ligand': if controller.command == 'fuzcav': from credovi.run import fuzcav fuzcav.do(controller) elif controller.command == 'molstrings': from credovi.run import molstrings molstrings.do(controller) elif controller.command == 'surfareas': from credovi.run import surfareas surfareas.do(controller) # close the application app.close()
def get_ligands(structure): """ Returns a list of ligand molecules found in the structure. """ ligands = [] # check if structure has any ligands at all app.log.debug("checking for ligands in structure {}...".format(structure.GetTitle())) if structure.HasData('ligand_entity_serials'): app.log.debug("structure {} has ligands. processing them.".format(structure.GetTitle())) ### create a mapping between atom ids and ligand entity serials for partitioning entity_serials = structure.GetData('ligand_entity_serials') partlist = OEIntArray(structure.GetMaxAtomIdx()) # create ligand partition list for atom in structure.GetAtoms(): entity_serial = atom.GetIntData('entity_serial') if entity_serial in entity_serials: partlist[atom.GetIdx()] = entity_serial ligpred = OEPartPredAtom(partlist) # create a new molecule for each ligand in the structure for entity_serial in entity_serials: ligpred.SelectPart(entity_serial) ligand = OEGraphMol() OESubsetMol(ligand, structure, ligpred) # remove pdb header from ligand OEClearPDBData(ligand) OEDeleteEverythingExceptTheFirstLargestComponent(ligand) # add the ligand to list if ligand.NumAtoms(): # get all the residues (components) of this ligand residues = set((OEAtomGetResidue(atom) for atom in ligand.GetAtoms())) # sort residues by residue number residues = sorted(residues, key=lambda r: r.GetResidueNumber()) # add information for single component ligand if len(residues) == 1: residue = residues.pop() pdb_chain_id, name, res_num = residue.GetPDBId()[:-1] ligand.SetIntData('res_num', res_num) # add information for peptide ligand only elif len(residues) <= 10: pdb_chain_id = residues[0].GetChainID() name = '-'.join((residue.GetName().strip() for residue in residues)) app.log.debug("chain {0} is peptide ligand with sequence {1}." .format(pdb_chain_id, name)) # ligand has too many residues - must be an error else: app.log.fatal("PDB {0}: ligand with entity serial number {1} has {2} residues - aborting!:\n{3}" .format(structure.GetTitle(), entity_serial, len(residues), residues)) app.close() # add required information to ligand molecule ligand.SetTitle(name) ligand.SetStringData('name', name) ligand.SetStringData('pdb_chain_id', pdb_chain_id) ligand.SetIntData('entity_serial', entity_serial) ligands.append(ligand) # something must have gotten wrong with the entity serial number else: app.log.warn('ligand with entity serial number {0} cannot be found in structure!' .format(entity_serial)) return ligands