def go(self, model_list = None, reference = None): """ Run benchmarking. @param model_list: list of models (default: None S{->} outFolder/L{F_PDBModels}) @type model_list: ModelList @param reference: reference model (default: None S{->} outFolder/L{F_INPUT_REFERENCE}) @type reference: PDBModel """ model_list = model_list or self.outFolder + self.F_PDBModels reference = reference or self.outFolder + self.F_INPUT_REFERENCE pdb_list = T.load('%s'%model_list) reference = PDBModel(reference) # check with python 2.4 iref, imodel = reference.compareAtoms(pdb_list[0]) mask_casting = N.zeros(len(pdb_list[0])) N.put(mask_casting, imodel, 1) reference = reference.take(iref) #reference_mask_CA = reference_rmsd.maskCA() atom_mask = N.zeros(len(pdb_list[0])) N.put(atom_mask,imodel,1) rmask = pdb_list[0].profile2mask("n_templates", 1,1000) amask = pdb_list[0].res2atomMask(rmask) mask_final_ref = N.compress(mask_casting, amask) mask_final = mask_casting * amask reference = reference.compress(mask_final_ref) for i in range(len(pdb_list)): #self.cad(reference, pdb_list[i]) pdb_list[i], pdb_wo_if = self.output_fittedStructures(\ pdb_list[i], reference, i, mask_final) fitted_model_if = pdb_list[i].compress(mask_final) fitted_model_wo_if = pdb_wo_if.compress(mask_final) coord1 = reference.getXyz() coord2 = fitted_model_if.getXyz() aprofile = self.rmsd_res(coord1,coord2) self.calc_rmsd(fitted_model_if, fitted_model_wo_if, reference, pdb_list[i]) pdb_list[i].atoms.set('rmsd2ref_if', aprofile, mask=mask_final, default = -1, comment="rmsd to known reference structure") self.output_rmsd_aa(pdb_list) self.output_rmsd_ca(pdb_list) self.output_rmsd_res(pdb_list) self.write_PDBModels(pdb_list)
def parmMirror( self, f_out, f_out_crd=None, fmod=['frcmod.ionsjc_tip3p'], fprep=[], **kw ): """ Create a parm7 file whose atom content (and order) exactly mirrors the given PDBModel. This requires two leap runs. First we get a temporary topology, then we identify all atoms added by leap and build a final topology where these atoms are deleted. This parm is hence NOT suited for simulations but can be used to parse e.g. a trajectory or PDB into ptraj. @param f_out: target parm file @type f_out: str @param f_out_crd: target crd file (default: f_out but ending .crd) @type f_out_crd: str @param fmod : list of amber Mod files (loaded with loadAmberParams) @type fmod : [str] @param fmod : list of amber Prep files (loaded with loadAmberPrep) @type fmod : [str] """ f_out = t.absfile( f_out ) f_out_crd = t.absfile( f_out_crd ) or t.stripSuffix( f_out ) + '.crd' ## if there are hydrogens, recast them to standard amber names aatm = 'HA' in self.m.atomNames() ## 'HB2' in self.m.atomNames() ## First leap round ## m_ref = self.m.clone() m_ref.xplor2amber( aatm=aatm, parm10=True ) tmp_in = tempfile.mktemp( 'leap_in0.pdb' ) m_ref.writePdb( tmp_in, ter=3 ) tmp_parm = tempfile.mktemp( '_parm0' ) tmp_crd = tempfile.mktemp( '_crd0' ) leap_mod = self.__fLines( 'm = loadAmberParams %s\n', fmod ) leap_prep= self.__fLines( 'loadAmberPrep %s\n', fprep ) self.__runLeap( self.script_mirror_pdb, leaprc=self.leaprc, fmod=leap_mod, fprep=leap_prep, in_pdb=tmp_in, out_parm=tmp_parm, out_crd=tmp_crd, delete_atoms='' ) tmp_pdb = self.parm2pdb( tmp_parm, tmp_crd, tempfile.mktemp( 'leap_out.pdb' ), aatm=aatm ) if not self.debug: t.tryRemove( tmp_parm ) t.tryRemove( tmp_crd ) t.tryRemove( tmp_in ) ## load model with missing atoms added by leap m_leap = PDBModel( tmp_pdb ) ## compare atom content iLeap, iRef = m_leap.compareAtoms( m_ref ) ## check that ref model doesn't need any change if iRef != range( len( m_ref ) ): uLeap, uRef = m_leap.unequalAtoms( m_ref, iLeap, iRef ) atms = m_ref.reportAtoms( uRef, n=6 ) raise AmberError, "Cannot create exact mirror of %s.\n" % tmp_in +\ "Leap has renamed/deleted original atoms in %s:\n"% tmp_pdb+\ atms ## indices of atoms that were added by leap delStr = self.__deleteAtoms( m_leap, self.__inverseIndices( m_leap, iLeap ) ) ## Second leap round ## self.__runLeap( self.script_mirror_pdb, leaprc=self.leaprc, in_pdb=tmp_pdb, fmod=leap_mod, fprep=leap_prep, out_parm=f_out, out_crd=f_out_crd, delete_atoms=delStr ) if not self.debug: t.tryRemove( tmp_pdb )
def go(self, model_list=None, reference=None): """ Run benchmarking. @param model_list: list of models (default: None S{->} outFolder/L{F_PDBModels}) @type model_list: ModelList @param reference: reference model (default: None S{->} outFolder/L{F_INPUT_REFERENCE}) @type reference: PDBModel """ model_list = model_list or self.outFolder + self.F_PDBModels reference = reference or self.outFolder + self.F_INPUT_REFERENCE pdb_list = T.load('%s' % model_list) reference = PDBModel(reference) # check with python 2.4 iref, imodel = reference.compareAtoms(pdb_list[0]) mask_casting = N0.zeros(len(pdb_list[0])) N0.put(mask_casting, imodel, 1) reference = reference.take(iref) #reference_mask_CA = reference_rmsd.maskCA() atom_mask = N0.zeros(len(pdb_list[0])) N0.put(atom_mask, imodel, 1) rmask = pdb_list[0].profile2mask("n_templates", 1, 1000) amask = pdb_list[0].res2atomMask(rmask) mask_final_ref = N0.compress(mask_casting, amask) mask_final = mask_casting * amask reference = reference.compress(mask_final_ref) for i in range(len(pdb_list)): #self.cad(reference, pdb_list[i]) pdb_list[i], pdb_wo_if = self.output_fittedStructures(\ pdb_list[i], reference, i, mask_final) fitted_model_if = pdb_list[i].compress(mask_final) fitted_model_wo_if = pdb_wo_if.compress(mask_final) coord1 = reference.getXyz() coord2 = fitted_model_if.getXyz() aprofile = self.rmsd_res(coord1, coord2) self.calc_rmsd(fitted_model_if, fitted_model_wo_if, reference, pdb_list[i]) pdb_list[i].atoms.set('rmsd2ref_if', aprofile, mask=mask_final, default=-1, comment="rmsd to known reference structure") self.output_rmsd_aa(pdb_list) self.output_rmsd_ca(pdb_list) self.output_rmsd_res(pdb_list) self.write_PDBModels(pdb_list)
def parmMirror(self, f_out, f_out_crd=None, fmod=['frcmod.ionsjc_tip3p'], fprep=[], **kw): """ Create a parm7 file whose atom content (and order) exactly mirrors the given PDBModel. This requires two leap runs. First we get a temporary topology, then we identify all atoms added by leap and build a final topology where these atoms are deleted. This parm is hence NOT suited for simulations but can be used to parse e.g. a trajectory or PDB into ptraj. @param f_out: target parm file @type f_out: str @param f_out_crd: target crd file (default: f_out but ending .crd) @type f_out_crd: str @param fmod : list of amber Mod files (loaded with loadAmberParams) @type fmod : [str] @param fmod : list of amber Prep files (loaded with loadAmberPrep) @type fmod : [str] """ f_out = t.absfile(f_out) f_out_crd = t.absfile(f_out_crd) or t.stripSuffix(f_out) + '.crd' ## if there are hydrogens, recast them to standard amber names aatm = 'HA' in self.m.atomNames() ## 'HB2' in self.m.atomNames() ## First leap round ## m_ref = self.m.clone() m_ref.xplor2amber(aatm=aatm, parm10=True) tmp_in = tempfile.mktemp('leap_in0.pdb') m_ref.writePdb(tmp_in, ter=3) tmp_parm = tempfile.mktemp('_parm0') tmp_crd = tempfile.mktemp('_crd0') leap_mod = self.__fLines('m = loadAmberParams %s\n', fmod) leap_prep = self.__fLines('loadAmberPrep %s\n', fprep) self.__runLeap(self.script_mirror_pdb, leaprc=self.leaprc, fmod=leap_mod, fprep=leap_prep, in_pdb=tmp_in, out_parm=tmp_parm, out_crd=tmp_crd, delete_atoms='') tmp_pdb = self.parm2pdb(tmp_parm, tmp_crd, tempfile.mktemp('leap_out.pdb'), aatm=aatm) if not self.debug: t.tryRemove(tmp_parm) t.tryRemove(tmp_crd) t.tryRemove(tmp_in) ## load model with missing atoms added by leap m_leap = PDBModel(tmp_pdb) ## compare atom content iLeap, iRef = m_leap.compareAtoms(m_ref) ## check that ref model doesn't need any change if iRef != range(len(m_ref)): uLeap, uRef = m_leap.unequalAtoms(m_ref, iLeap, iRef) atms = m_ref.reportAtoms(uRef, n=6) raise AmberError, "Cannot create exact mirror of %s.\n" % tmp_in +\ "Leap has renamed/deleted original atoms in %s:\n"% tmp_pdb+\ atms ## indices of atoms that were added by leap delStr = self.__deleteAtoms(m_leap, self.__inverseIndices(m_leap, iLeap)) ## Second leap round ## self.__runLeap(self.script_mirror_pdb, leaprc=self.leaprc, in_pdb=tmp_pdb, fmod=leap_mod, fprep=leap_prep, out_parm=f_out, out_crd=f_out_crd, delete_atoms=delStr) if not self.debug: t.tryRemove(tmp_pdb)