def test_set_protein_traj(self): oetraj_record = self.record.get_value(OEField('OETraj', Types.Record)) prot_mol = oetraj_record.get_value(Fields.protein_traj_confs) mdrecord = MDDataRecord(oetraj_record) oetraj_record.delete_field(Fields.protein_traj_confs) with self.assertRaises(ValueError): mdrecord.get_protein_traj self.assertTrue(mdrecord.set_protein_traj(prot_mol))
def process(self, record, port): try: # The copy of the dictionary option as local variable # is necessary to avoid filename collisions due to # the parallel cube processes opt = dict(self.opt) # Create the MD record to use the MD Record API mdrecord = MDDataRecord(record) # Logger string opt['Logger'].info(' ') system_title = mdrecord.get_title #sys_id = mdrecord.get_flask_id opt['Logger'].info( '{}: Attempting MD Traj conversion into OEMols'.format( system_title)) traj_fn = mdrecord.get_stage_trajectory() opt['Logger'].info('{} Temp Directory: {}'.format( system_title, os.path.dirname(traj_fn))) opt['Logger'].info('{} Trajectory filename: {}'.format( system_title, traj_fn)) # Generate multi-conformer protein and ligand OEMols from the trajectory opt['Logger'].info( '{} Generating protein and ligand trajectory OEMols'.format( system_title)) flask = mdrecord.get_flask md_components = record.get_value(Fields.md_components) # opt['Logger'].info(md_components.get_info) # Check Ligand Isomeric Smiles lig_comp = md_components.get_ligand lig_ref = record.get_value(Fields.ligand) smi_lig_comp = oechem.OECreateSmiString(lig_comp) smi_lig_ref = oechem.OECreateSmiString(lig_ref) if smi_lig_ref != smi_lig_comp: raise ValueError( "Ligand Isomeric Smiles String check failure: {} vs {}". format(smi_lig_comp, smi_lig_ref)) ptraj, ltraj, wtraj = utl.extract_aligned_prot_lig_wat_traj( md_components, flask, traj_fn, opt, water_cutoff=opt['water_cutoff']) ltraj.SetTitle(record.get_value(Fields.ligand_name)) ptraj.SetTitle(record.get_value(Fields.protein_name)) opt['Logger'].info( '{} #atoms, #confs in protein traj OEMol: {}, {}'.format( system_title, ptraj.NumAtoms(), ptraj.NumConfs())) opt['Logger'].info( '{} #atoms, #confs in ligand traj OEMol: {}, {}'.format( system_title, ltraj.NumAtoms(), ltraj.NumConfs())) opt['Logger'].info( '{} #atoms, #confs in water traj OEMol: {}, {}'.format( system_title, wtraj.NumAtoms(), wtraj.NumConfs())) # Create new record with OETraj results oetrajRecord = OERecord() oetrajRecord.set_value(OEField('LigTraj', Types.Chem.Mol), ltraj) if wtraj: oetrajRecord.set_value(OEField('WatTraj', Types.Chem.Mol), wtraj) if in_orion(): oetrajRecord.set_value(Fields.collection, mdrecord.collection_id) mdrecord_traj = MDDataRecord(oetrajRecord) mdrecord_traj.set_protein_traj(ptraj, shard_name="ProteinTrajConfs_") record.set_value(Fields.Analysis.oetraj_rec, oetrajRecord) # update or initiate the list of analyses that have been done if record.has_value(Fields.Analysis.analysesDone): analysesDone = utl.RequestOEFieldType( record, Fields.Analysis.analysesDone) analysesDone.append('OETraj') else: analysesDone = ['OETraj'] record.set_value(Fields.Analysis.analysesDone, analysesDone) opt['Logger'].info( '{}: saved protein, ligand and water traj OEMols'.format( system_title)) self.success.emit(record) del mdrecord del mdrecord_traj except Exception as e: print("Failed to complete", str(e), flush=True) self.log.error(traceback.format_exc()) # Return failed mol self.failure.emit(record) return
def process(self, record, port): try: # The copy of the dictionary option as local variable # is necessary to avoid filename collisions due to # the parallel cube processes opt = dict(self.opt) # Logger string opt['Logger'].info(' Beginning ConfTrajsToLigTraj') system_title = utl.RequestOEFieldType(record, Fields.title) opt['Logger'].info( '{} Attempting to combine conf traj OEMols into ligand traj OEMol' .format(system_title)) # Go find the ligand and LigTraj fields in each of the conformer records if not record.has_field(Fields.Analysis.oetrajconf_rec): raise ValueError( '{} could not find the conformer record'.format( system_title)) else: opt['Logger'].info( '{} found the conformer record'.format(system_title)) # set up ligand and LigTraj lists then loop over conformer records poseIdVec = [] ligTrajConfs = [] protTrajConfs = [] watTrajConfs = [] list_conf_rec = record.get_value(Fields.Analysis.oetrajconf_rec) for confrec in list_conf_rec: confid = utl.RequestOEFieldType(confrec, Fields.confid) if not confrec.has_field(Fields.Analysis.oetraj_rec): raise ValueError( '{} confID {}: could not find traj record'.format( system_title, confid)) oetrajRecord = confrec.get_value(Fields.Analysis.oetraj_rec) # Extract the ligand traj OEMol from the OETraj record ligTraj = utl.RequestOEField(oetrajRecord, 'LigTraj', Types.Chem.Mol) poseIdVec += [confid] * ligTraj.NumConfs() ligTrajConfs.append(ligTraj) opt['Logger'].info( '{} confID {}: adding ligTraj with {} atoms, {} confs'. format(system_title, confid, ligTraj.NumAtoms(), ligTraj.NumConfs())) # Extract the activeSite water traj OEMol from the OETraj record watTraj = utl.RequestOEField(oetrajRecord, 'WatTraj', Types.Chem.Mol) watTrajConfs.append(watTraj) opt['Logger'].info( '{} confID {}: adding watTraj with {} atoms, {} confs'. format(system_title, confid, watTraj.NumAtoms(), watTraj.NumConfs())) # Extract the protTraj OEMol from the OETraj record mdtrajrecord = MDDataRecord(oetrajRecord) protTraj = mdtrajrecord.get_protein_traj protTrajConfs.append(protTraj) opt['Logger'].info( '{} confID {}: adding protTraj with {} atoms, {} confs'. format(system_title, confid, protTraj.NumAtoms(), protTraj.NumConfs())) del mdtrajrecord if len(ligTrajConfs) < 1 or len(protTrajConfs) < 1: raise ValueError( '{} empty list of lig or protein trajectory OEMols'.format( system_title)) ligTraj = oechem.OEMol(ligTrajConfs[0]) xyz = oechem.OEFloatArray(3 * ligTraj.GetMaxAtomIdx()) for trajMol in ligTrajConfs[1:]: for conf in trajMol.GetConfs(): conf.GetCoords(xyz) ligTraj.NewConf(xyz) opt['Logger'].info( '{} composite ligTraj has {} atoms, {} confs'.format( system_title, ligTraj.NumAtoms(), ligTraj.NumConfs())) watTraj = oechem.OEMol(watTrajConfs[0]) xyz = oechem.OEFloatArray(3 * watTraj.GetMaxAtomIdx()) for trajMol in watTrajConfs[1:]: for conf in trajMol.GetConfs(): conf.GetCoords(xyz) watTraj.NewConf(xyz) opt['Logger'].info( '{} composite watTraj has {} atoms, {} confs'.format( system_title, watTraj.NumAtoms(), watTraj.NumConfs())) protTraj = protTrajConfs[0] xyz = oechem.OEFloatArray(3 * protTraj.GetMaxAtomIdx()) for trajMol in protTrajConfs[1:]: for conf in trajMol.GetConfs(): conf.GetCoords(xyz) protTraj.NewConf(xyz) opt['Logger'].info( '{} composite protTraj has {} atoms, {} confs'.format( system_title, protTraj.NumAtoms(), protTraj.NumConfs())) record.set_value(Fields.Analysis.poseIdVec, poseIdVec) # Create new record with OETraj results oetrajRecord = OERecord() oetrajRecord.set_value(OEField('LigTraj', Types.Chem.Mol), ligTraj) if watTraj: oetrajRecord.set_value(OEField('WatTraj', Types.Chem.Mol), watTraj) if in_orion(): collection_id = utl.RequestOEFieldType(record, Fields.collection) oetrajRecord.set_value(Fields.collection, collection_id) mdrecord_traj = MDDataRecord(oetrajRecord) mdrecord_traj.set_protein_traj(protTraj, shard_name="ProteinTrajConfs_") record.set_value(Fields.Analysis.oetraj_rec, oetrajRecord) self.success.emit(record) except Exception as e: print("Failed to complete", str(e), flush=True) opt['Logger'].info( 'Exception {} in ConfTrajsToLigTraj on {}'.format( str(e), system_title)) self.log.error(traceback.format_exc()) # Return failed mol self.failure.emit(record) return