def create_model(self, model_id, alignment): # base_models_tuple, target_id,pdb_id,pdb_chain,aln_target,aln_pdb current_dir = os.getcwd() org_stdout = sys.stdout # store original stdout object for later # query,template = (alignment.query_record(),alignment.hit_record()) query, template = (SeqRecord(Seq(alignment.aln_query.seq), id=alignment.aln_query.name), SeqRecord(Seq(alignment.aln_hit.seq), id=alignment.aln_hit.name)) self._create_directory_structure(model_id, query.id) sys.stdout = open(self.log_path(model_id, query.id), "w") try: env = environ() env.io.atom_files_directory = self.pdbs_dir os.chdir(self.model_directory(model_id, query.id)) # #align_models = self._create_aligment( env, base_models) align_models = self.aln2pir(model_id, alignment, query, template) # self._create_models(env, align_models, model_id, query.id) # return [ self.pdb_path(model_id, query.id, i) for i in range(1, self.model_count + 1) ] # # # finally: sys.stdout.close() sys.stdout = org_stdout os.chdir(current_dir)
def main(args): mod.log.verbose() env = mod.environ() env.io.atom_files_directory = [".", args.dir, "../" + args.dir] aln = mod.alignment(env) mdl = mod.model( env, file=args.template, model_segment=( "FIRST:" + args.chains[0].upper(), "LAST:" + args.chains[1].upper(), ), ) aln.append_model( mdl, align_codes=args.template.replace(".pdb", ""), atom_files=args.template ) sequence_file = os.path.join(args.dir, args.target) sequence_code = args.target.replace(".ali", "") aln.append(file=sequence_file, align_codes=sequence_code) aln.align2d() # perform alignment align_file = os.path.join( args.dir, sequence_code + "-" + args.template.replace(".pdb", "") ) aln.write(file=align_file + ".ali", alignment_format="PIR") # para o modeller aln.write(file=align_file + ".pap", alignment_format="PAP") # +fácil de ler # check files aln.check()
def soap_pp(wrkdir): """ Get SOAP-PP Pair score for protein-protein. PDB must contain only two chains. Do not compute the SOAP-PP Atom score. [1] G. Q. Dong, H. Fan, D. Schneidman-Duhovny, B. Webb, and A. Sali, "Optimized atomic statistical potentials: assessment of protein interfaces and loops", Bioinformatics, vol. 29, no. 24, pp. 3158-3166, 2013. """ import modeller import modeller.scripts import modeller.soap_pp time_start = timer() log.info("Getting SOAP-PP-Pair scoring...") cpx = os.path.join(wrkdir, 'complexAB.pdb') with open(os.path.join(wrkdir, "soap_pp_pair.out"), "w") as fp: _stdout = sys.stdout sys.stdout = fp env = modeller.environ() env.libs.topology.read(file='$(LIB)/top_heav.lib') env.libs.parameters.read(file='$(LIB)/par.lib') mdl = modeller.scripts.complete_pdb(env, cpx) cpx = modeller.selection(mdl.chains[:]) soap_pp_pair = modeller.soap_pp.PairScorer() score = cpx.assess(soap_pp_pair) sys.stdout.flush() sys.stdout = _stdout desc = dict() desc['SOAP-PP-Pair'] = score time_end = timer() desc['>TIME_SOAP-PP-Pair'] = time_end - time_start return desc
def test_script9(self): """Test step 9 (multiple fitting)""" # Get inputs (outputs from step 8) for i in ('top', 'bottom'): shutil.copy('precalculate_results/stage8_split_density/' \ 'groel-11.5A.%s.mrc' % i, 'output') # Make sure the script runs without errors p = subprocess.check_call(['scripts/' \ 'script9_symmetric_multiple_fitting.py']) e = modeller.environ() ref = modeller.model(e, file='precalculate_results/stage9_symmetric_multiple_fitting/' \ 'model.top.0.pdb') sel = modeller.selection(ref).only_atom_types('CA') # At least one model in each ring should be close to the reference for side in ('top', 'bottom'): rms = [] for i in range(6): fname = 'output/model.%s.%d.pdb' % (side, i) m = modeller.model(e, file=fname) a = modeller.alignment(e) a.append_model(ref, align_codes='ref') a.append_model(m, align_codes='model') rms.append(sel.superpose(m, a).rms) os.unlink(fname) self.assertTrue(min(rms) < 10.0) os.unlink('output/intermediate_asmb_sols.out') for side in ('top', 'bottom'): os.unlink('output/multifit.%s.output' % side) os.unlink('output/multifit.%s.output.symm.ref' % side) os.unlink('output/multifit.%s.param' % side)
def test_script6(self): """Test step 6 (model building and assessment)""" # Get inputs (outputs from steps 3 and 5) shutil.copy('precalculate_results/stage3_density_segmentation/' \ 'groel_subunit_11.mrc', 'output') shutil.copy('precalculate_results/stage5_template_alignment/' \ 'groel-1iokA.ali', 'output') # Make sure the script runs without errors p = subprocess.check_call(['scripts/' \ 'script6_model_building_and_assessment.py']) # Check output models e = modeller.environ() for i in range(1, 11): base = 'output/P0A6F5.B9999%04d' % i pdb = base + '.pdb' trunc_pdb = base + '.truncated.pdb' trunc_fit_pdb = base + '.truncated.fitted.pdb' m = modeller.model(e, file=pdb) self.assertEqual(len(m.residues), 548) m = modeller.model(e, file=trunc_pdb) self.assertEqual(len(m.residues), 524) m = modeller.model(e, file=trunc_fit_pdb) self.assertEqual(len(m.residues), 524) os.unlink(pdb) os.unlink(trunc_pdb) os.unlink(trunc_fit_pdb) scores = 'output/model_building.scores.output' wc = len(open(scores).readlines()) # Should be one line for each of 10 models, plus a header self.assertEqual(wc, 11) os.unlink(scores)
def test_glyc(self): """Test glycosylation benchmark""" os.chdir(os.path.join(TOPDIR, 'benchmark', 'input_glyc')) # Cleanup anything left over from a previous run shutil.rmtree('pred_dECALCrAS1000', ignore_errors=True) subprocess.check_call(['allosmod', 'setup']) # Setup should generate ligand and script: for f in ['lig.pdb', 'qsub.sh']: self.assertTrue(os.path.exists(f)) # Run the protocol subprocess.check_call(['/bin/sh', '--login', './qsub.sh']) # Should generate more files: os.chdir('pred_dECALCrAS1000/2AAS.pdb_0') for f in ['align2.ali', 'allosmod.py', 'converted.rsr', 'model_glyc.log', 'model_glyc.py', 'pm.pdb.B99990001.pdb', 'pm.pdb.D00000001', 'pm.pdb.V99990001', 'run.log']: self.assertTrue(os.path.exists(f)) # Generated model should have sugars added to second chain e = modeller.environ() e.io.hetatm = True m = modeller.model(e, file='pm.pdb.B99990001.pdb') self.assertEqual(len(m.chains), 2) self.assertEqual(len(m.chains[0].residues), 124) self.assertEqual(len(m.chains[1].residues), 16) self.assertEqual([r.name for r in m.chains[1].residues], ['NAG', 'NAG', 'BMA', 'MAN', 'MAN', 'MAN', 'MAN', 'MAN', 'NAG', 'NAG', 'BMA', 'MAN', 'MAN', 'MAN', 'MAN', 'MAN'])
def agbnp(wrkdir): """ Get AGBNP solvation term for protein-protein as implemented in modeller. [1] E. Gallicchio and R. M. Levy, "AGBNP: An analytic implicit solvent model suitable for molecular dynamics simulations and high-resolution modeling", Journal of Computational Chemistry, vol. 25, no. 4, pp. 479-499, 2004. """ import modeller import modeller.scripts time_start = timer() log.info("Getting AGBNP scoring...") cpx = os.path.join(wrkdir, 'complexAB.pdb') with open(os.path.join(wrkdir, "agbnp.out"), "w") as fp: _stdout = sys.stdout sys.stdout = fp env = modeller.environ() env.libs.topology.read(file='$(LIB)/top_heav.lib') env.libs.parameters.read(file='$(LIB)/par.lib') mdl = modeller.scripts.complete_pdb(env, cpx) cpx = modeller.selection(mdl.chains[:]) lig = modeller.selection(mdl.chains[0]) rec = modeller.selection(mdl.chains[1]) agbnp = AGBNPScorer() score = cpx.assess(agbnp) - rec.assess(agbnp) - lig.assess(agbnp) sys.stdout.flush() sys.stdout = _stdout desc = dict() desc['AGBNP'] = score time_end = timer() desc['>TIME_AGBNP'] = time_end - time_start return desc
def _align_structures(structures, verbose): """Aligns structures using iterative structural alignment.""" # set up modeller environment if verbose: modeller.log.verbose() else: modeller.log.none() env = modeller.environ() aln = modeller.alignment(env) # read structures into modeller environment for (id, structure) in structures.items(): mdl = modeller.model(env, file=structure) aln.append_model(mdl, align_codes=id, atom_files=structure) # align structures using iterative structural alignment modeller.salign.iterative_structural_align(aln) # convert modeller alignment to Alignment object mod_aln_f = tempfile.NamedTemporaryFile(mode='w', prefix=fnameprefix, suffix='.ali', delete=False) mod_aln_fname = mod_aln_f.name mod_aln_f.close() aln.write(mod_aln_fname, alignment_format='PIR') alnobj = Alignment(mod_aln_fname) os.remove(mod_aln_fname) return alnobj
def get_sas(pdb,probe): import modeller # Read the PDB file env = modeller.environ() mdl = modeller.model(env) mdl.read(file=pdb) # Calculate atomic accessibilities (in Biso) with appropriate probe_radius myedat = modeller.energy_data() myedat.radii_factor = 1.6 mdl.write_data(edat=myedat, output='PSA ATOMIC_SOL', psa_integration_step=0.05, probe_radius=probe) mdl.write(file=pdb.rsplit('.',1)[0]+'.sas') # read SAS with open('%s.sas' % (pdb.rsplit('.',1)[0], )) as data: D = data.readlines() Sas = {} for d in D: d = d.strip() if d[:4]=='ATOM': atom, res, resid, cid = d[12:16], d[17:20], int(d[22:26]), d[21] if cid == ' ': cid='A' Sas[(atom,res,resid,cid)] = float(d[60:66]) return Sas
def get_sas(pdb, probe): import modeller # Read the PDB file env = modeller.environ() mdl = modeller.model(env) mdl.read(file=pdb) # Calculate atomic accessibilities (in Biso) with appropriate probe_radius myedat = modeller.energy_data() myedat.radii_factor = 1.6 mdl.write_data(edat=myedat, output="PSA ATOMIC_SOL", psa_integration_step=0.05, probe_radius=probe) mdl.write(file=pdb.rsplit(".", 1)[0] + ".sas") # read SAS with open("%s.sas" % (pdb.rsplit(".", 1)[0],)) as data: D = data.readlines() Sas = {} for d in D: d = d.strip() if d[:4] == "ATOM": atom, res, resid, cid = d[12:16], d[17:20], int(d[22:26]), d[21] if cid == " ": cid = "A" Sas[(atom, res, resid, cid)] = float(d[60:66]) return Sas
def make_model( self, template_system: ProteinStructure, target_sequence: KinaseDomainAminoAcidSequence, alignment: Alignment, num_models: int = 100, ligand: bool = False, ): """ Generate homology model(s) based on a template and alignment with MODELLER Parameters ---------- template_system: ProteinStructure The template system. target_sequence: KinaseDomainAminoAcidSequence The target sequence alignment: Alignment An Alignment object containing information on aligned sequences. These sequences must be the same as present in template_system and target_sequence num_models: int The number of homology models to generate. default = 100 ligand: bool Specify whether to include a bound ligand present in the template structure. (Default: False) Returns ------- """ from modeller import log, environ from modeller.automodel import dope_loopmodel, assess log.verbose() env = environ() pdb_id = template_system.metadata["id"] env.io.atom_files_directory = [ template_system.metadata["path"].split(".")[0].split(pdb_id)[0] ] if ligand: # Read in HETATM records from template env.io.hetatm = True # TODO handle usage of "ncbi" instead of "uniprot_id" # specify model paramters and score via DOPE a = dope_loopmodel( env, alnfile=alignment.alignment_file_path, knowns=template_system.metadata["id"], sequence=target_sequence.metadata["uniprot_id"], loop_assess_methods=(assess.DOPE, assess.GA341), ) a.starting_model = 1 a.ending_model = num_models # TODO could add loop refinement option here # TODO need to specify output directory for models a.make()
def align_template_to_reference(msmseed, ref_msmseed): import modeller import tempfile import shutil import copy import os temp_dir = tempfile.mkdtemp() try: os.chdir(temp_dir) alignment_file = open('aln_tmp.pir','w') aln = _PIR_alignment(ref_msmseed.template_sequence, ref_msmseed.template_id, msmseed.template_sequence, msmseed.template_id) alignment_file.writelines(aln) alignment_file.close() template_file = open(msmseed.template_id + '.pdb','w') template_pdb = msmseed.template_structure template_pdb.writeFile(template_pdb.topology, template_pdb.positions, template_file) template_file.close() ref_pdb = ref_msmseed.template_structure ref_file = open(ref_msmseed.template_id + '.pdb', 'w') ref_pdb.writeFile(ref_pdb.topology, ref_pdb.positions, ref_file) ref_file.close() modeller.log.none() env = modeller.environ() env.io.atom_files_directory = temp_dir aln = modeller.alignment(env, file='aln_tmp.pir', align_codes=(ref_msmseed.template_id, msmseed.template_id)) mdl = modeller.model(env, file=ref_msmseed.template_id + '.pdb') mdl2 = modeller.model(env, file=msmseed.template_id+'.pdb') atmsel = modeller.selection(mdl).only_atom_types('CA') r = atmsel.superpose(mdl2, aln) msmseed.rmsd_to_reference = copy.deepcopy(r.rms) except Exception as e: msmseed.error_message = e.message finally: shutil.rmtree(temp_dir) return msmseed
def main(args): mod.log.verbose() env = mod.environ() env.io.atom_files_directory = [".", args.dir, "../" + args.dir] env.libs.topology.read(file="$(LIB)/top_heav.lib") # read topology env.libs.parameters.read(file="$(LIB)/par.lib") # read parameters # assess model using DOPE model = complete_pdb(env, args.model) # read model file s = mod.selection(model) # all atoms selection s.assess_dope( output="ENERGY_PROFILE NO_REPORT", file=args.model.replace(".pdb", ".profile"), normalize_profile=True, smoothing_window=15, ) # assess template using DOPE template = complete_pdb( env, args.template, model_segment=( "FIRST:" + args.chains[0].upper(), "LAST:" + args.chains[1].upper(), ), ) s = mod.selection(template) # all atoms selection s.assess_dope( output="ENERGY_PROFILE NO_REPORT", file=args.template.replace(".pdb", ".profile"), normalize_profile=True, smoothing_window=15, )
def dope(wrkdir): """ Get DOPE and DOPE-HRS scores for protein-protein. PDB must contain only two chains. [1] M. Shen and A. Sali, "Statistical potential for assessment and prediction of protein structures", Protein Science, vol. 15, no. 11, pp. 2507-2524, 2006. """ import modeller import modeller.scripts time_start = timer() log.info("Getting DOPE and DOPE-HR scoring...") cpx = os.path.join(wrkdir, 'complexAB.pdb') with open(os.path.join(wrkdir, "dope.out"), "w") as fp: _stdout = sys.stdout sys.stdout = fp env = modeller.environ() env.libs.topology.read(file='$(LIB)/top_heav.lib') env.libs.parameters.read(file='$(LIB)/par.lib') mdl = modeller.scripts.complete_pdb(env, cpx) cpx = modeller.selection(mdl.chains[:]) lig = modeller.selection(mdl.chains[0]) rec = modeller.selection(mdl.chains[1]) dope = cpx.assess_dope() - rec.assess_dope() - lig.assess_dope() dopehr = cpx.assess_dopehr() - rec.assess_dopehr() - lig.assess_dopehr() sys.stdout.flush() sys.stdout = _stdout desc = dict() desc['DOPE'] = dope desc['DOPE-HR'] = dopehr time_end = timer() desc['>TIME_DOPE'] = time_end - time_start return desc
def run_modeller(target, template, model_dir, model_pdbfilepath, model_pdbfilepath_uncompressed, template_structure_dir, aln_filepath='alignment.pir', write_modeller_restraints_file=False): modeller.log.none() env = modeller.environ() env.io.atom_files_directory = [template_structure_dir] a = modeller.automodel.allhmodel(env, alnfile=aln_filepath, knowns=template.id, sequence=target.id) a.make() # do homology modeling save_modeller_output_files( target, model_dir, a, env, model_pdbfilepath, model_pdbfilepath_uncompressed, write_modeller_restraints_file=write_modeller_restraints_file)
def main(): import modeller ff1, ff2, aln_file, opts = parse_args() env = modeller.environ() # Read in HETATM records from template PDBs env.io.hetatm = True aln = salign0(env, ff1, ff2) aln.write(file=aln_file)
def make_model(msmseed): """ Use MODELLER from the Sali lab to create a model between the target and template specified in the input Parameters ---------- msmseed : MSMSeed object containing the alignment between target and template and template structure Returns ------- msmseed : MSMSeed object containing the homology model built from the input alignment and template structure """ import tempfile import os import modeller import modeller.automodel import shutil import simtk.openmm.app as app #if the target and template are the same, modeller dies. if msmseed.template_id == msmseed.target_id: msmseed.target_model = msmseed.template_structure return msmseed #first, we need to make a temp directory where we can put the files MODELLER needs temp_dir = tempfile.mkdtemp() try: os.chdir(temp_dir) alignment_file = open('aln_tmp.pir','w') alignment_file.writelines(msmseed.alignment) alignment_file.close() template_file = open(msmseed.template_id + '.pdb','w') template_pdb = msmseed.template_structure template_pdb.writeFile(template_pdb.topology, template_pdb.positions, template_file) template_file.close() modeller.log.none() env = modeller.environ() env.io.atom_files_directory = temp_dir a = modeller.automodel.allhmodel(env, # file with template codes and target sequence alnfile = 'aln_tmp.pir', # PDB codes of the template knowns = msmseed.template_id, # code of the target sequence = msmseed.target_id) a.make() tmp_model_pdbfilename = a.outputs[0]['name'] target_model = modeller.model(env, file=tmp_model_pdbfilename) msmseed.sequence_similarity = target_model.seq_id msmseed.target_model = app.PDBFile(tmp_model_pdbfilename) msmseed.target_restraints = open('%s.rsr' % msmseed.target_id, 'r').readlines() except: msmseed.error_state = -1 finally: shutil.rmtree(temp_dir) return msmseed
def perform_sequence_alignment(): e = modeller.environ() m1 = modeller.model(e, file='experimental.pdb') m2 = modeller.model(e, file='rosetta.pdb') aln = modeller.alignment(e) aln.append_model(m1, align_codes='experimental', atom_files='experimental.pdb') aln.append_model(m2, align_codes='rosetta') aln.align2d() aln.write(file='align.ali', alignment_format='PIR')
def test_detect_invalid_residue_types_ok(self): """Test _detect_invalid_residue_types() with OK sequence""" with utils.temporary_directory() as tmpdir: fname = os.path.join(tmpdir, 'test.pdb') with open(fname, 'w') as fh: fh.write(pdb_line + '\n') e = modeller.environ() m = modeller.model(e, file=fname) cleaning._detect_invalid_residue_types(m)
def _initialize_env(self, use_hetatm=True, use_water=True): env = modeller.environ() env.io.atom_files_directory = [] env.io.atom_files_directory.append(".") env.io.hetatm = use_hetatm env.io.water = use_water env.libs.topology.read(file='$(LIB)/top_heav.lib') env.libs.parameters.read(file='$(LIB)/par.lib') return env
def get_environ(self): """Get a Modeller environ object""" if not hasattr(self, '_modeller_environ'): # Speed tests up a little by only creating this object once env = modeller.environ() env.libs.topology.read('${LIB}/top_heav.lib') env.libs.parameters.read('${LIB}/par.lib') Tests._modeller_environ = env return self._modeller_environ
def test_script5(self): """Test step 5 (template alignment)""" # Make sure the script runs without errors p = subprocess.check_call(['scripts/script5_template_alignment.py']) # Check output alignment e = modeller.environ() a = modeller.alignment(e, file='output/groel-1iokA.ali') self.assertEqual([x.code for x in a], ['1iok', 'P0A6F5']) os.unlink('output/groel-1iokA.ali')
def test_integrative_modeling(self): """Test the entire integrative modeling run""" import modeller # Compile the clustering program subprocess.check_call(['gfortran', 'cluster.f', 'u3best.f', '-o', 'cluster.x'], cwd='integrative_modeling/bin') # Run sampling subprocess.check_call(['./run_modeling.py'], cwd='integrative_modeling') # Analysis subprocess.check_call(['bin/get_frames.sh'], cwd='integrative_modeling') # Make sure that at least two of the three "known good" clusters # are reproduced clusters = glob.glob('integrative_modeling/clustering/clus.*.pdb') clusters = [x for x in clusters if '-' not in x] exp_clusters = glob.glob('model_refinement/cluster*/model.pdb') env = modeller.environ() n_cluster = 0 rms = [] cluster_match = [0] * len(clusters) exp_cluster_match = [0] * len(exp_clusters) # Get a matrix of RMSD between all clusters and the expected clusters for ncluster, cluster in enumerate(clusters): per_cluster = [] for nexp_cluster, exp_cluster in enumerate(exp_clusters): mc = modeller.model(env, file=cluster) s = modeller.selection(mc) a = modeller.alignment(env) me = modeller.model(env, file=exp_cluster) a.append_model(mc, align_codes='clus') a.append_model(me, align_codes='exp_clus') # We only care about the global (non-cutoff) RMSD, so use a # large cutoff so that refine_local doesn't increase the number # of equivalent positions at the expense of worsening the RMSD r = s.superpose(me, a, rms_cutoff=999.) if r.rms < 15.0: cluster_match[ncluster] += 1 exp_cluster_match[nexp_cluster] += 1 per_cluster.append(r.rms) rms.append(per_cluster) # Count the number of clusters which are close to an expected cluster ncluster_match = len(cluster_match) - cluster_match.count(0) # Count the number of expected clusters which are close to a cluster nexp_cluster_match = len(exp_cluster_match) - exp_cluster_match.count(0) # Make sure that at least 2 of the 3 expected clusters is close to one # of the clusters we produced (but not all the *same* cluster) self.assertTrue(ncluster_match >= 2 and nexp_cluster_match >= 2, "Could not find any match between the %d clusters " "found in this test and 2 of the 3 'known good' " "clusters (match defined as all-atom RMSD less than " "15.0A). RMSD matrix: %s" % (len(clusters), str(rms)))
def make_model(self): import modeller env = modeller.environ() env.edat.dynamic_sphere= False with open('test.pdb', 'w') as fh: fh.write("ATOM 2 CA ALA 1 27.449 14.935 5.140 1.00 29.87 C\n") m = modeller.model(env, file='test.pdb') os.unlink('test.pdb') return m
def setupENV(): #setup Modeller env = modeller.environ() MPATH=epmv.__path__[0]+'/extension/Modeller/' env.io.atom_files_directory = [MPATH] env.edat.dynamic_sphere = True env.libs.topology.read(file='$(LIB)/top_heav.lib') env.libs.parameters.read(file='$(LIB)/par.lib') return env
def setupENV(): #setup Modeller env = modeller.environ() MPATH = epmv.__path__[0] + '/extension/Modeller/' env.io.atom_files_directory = [MPATH] env.edat.dynamic_sphere = True env.libs.topology.read(file='$(LIB)/top_heav.lib') env.libs.parameters.read(file='$(LIB)/par.lib') return env
def spline(pdb_file, in_restraints, out_restraints): import modeller # Needed to keep our custom form alive for restraints.read() from allosmod.modeller.forms import TruncatedGaussian e = modeller.environ() m = modeller.model(e, file=pdb_file) m.restraints.read(file=in_restraints) convert_restraints(m.restraints) m.restraints.write(file=out_restraints)
def mk_strct_al_modeller(strct_data1, strct_data2): _stdout = sys.stdout sys.stdout = open(os.devnull, 'w') tmp_file = tempfile.NamedTemporaryFile(suffix=".fasta", delete=False) env = m.environ() aln = m.alignment(env) code1 = 'pdb' + strct_data1['id'] code2 = 'pdb' + strct_data2['id'] chain1 = strct_data1['chain_id'] chain2 = strct_data2['chain_id'] env.io.atom_files_directory = ['.', PDB_DIR] result = {} try: for (code, chain) in ((code1, chain1), (code2, chain2)): mdl = m.model(env, file=code, model_segment=('FIRST:'+chain, 'LAST:'+chain)) aln.append_model(mdl, atom_files=code, align_codes=code+chain) for (weights, write_fit, whole) in (((1., 0., 0., 0., 1., 0.), False, True), ((1., 0.5, 1., 1., 1., 0.), False, True), ((1., 1., 1., 1., 1., 0.), True, False)): r = aln.salign(rms_cutoff=3.5, normalize_pp_scores=False, rr_file='$(LIB)/as1.sim.mat', overhang=30, gap_penalties_1d=(-450, -50), gap_penalties_3d=(0, 3), gap_gap_score=0, gap_residue_score=0, alignment_type='tree', # If 'progresive', the tree is not # computed and all structures will be # aligned sequentially to the first #ext_tree_file='1is3A_exmat.mtx', # Tree building can be avoided # if the tree is input feature_weights=weights, # For a multiple sequence alignment only # the first feature needs to be non-zero improve_alignment=True, fit=True, write_fit=False, write_whole_pdb=whole, output='ALIGNMENT QUALITY') if r.qscorepct > 70: aln.write(file=tmp_file.name, alignment_format='FASTA') with open(tmp_file.name) as a: alignment = unwrap(a.read().splitlines()) for i in range(len(alignment[1])): if alignment[1] != '-' and alignment[3] != '-': pos1 = get_real_position_al(alignment[1], i) pos2 = get_real_position_al(alignment[3], i) result[pos1] = pos2 except: print 'Modeller failed' sys.stdout.close() sys.stdout = _stdout return result
def _modeller_auto_alignment(self, chain, dummy_align_file): """ """ env = modeller.environ() model = modeller.automodel.automodel(env, alnfile=dummy_align_file, knowns=self._id, sequence=self._id + chain + "_full") model.auto_align() return None
def assessNormalizedDopeScore(pdb): if _MODELLER_MESSAGE != "": raise ImportError(_MODELLER_MESSAGE) env = modeller.environ() env.libs.topology.read(file='$(LIB)/top_heav.lib') # TODO: Test on Windows env.libs.parameters.read(file='$(LIB)/par.lib') # Read a model previously generated by Modeller's automodel class mdl = modeller.scripts.complete_pdb(env, pdb) zscore = mdl.assess_normalized_dope() return zscore
def main(argv): wp = '' mp = '' tp = '' try: opts, args = getopt.getopt(argv, "hw:m:t:", ["wprofile=", "mprofile=", "tprofile="]) except getopt.GetoptError: print( '%s -w wt_model_profile -m mt_model_profile -t template_profile' % sys.argv[0]) sys.exit(2) for opt, arg in opts: if opt in ('-h', '--help'): print( '%s -w wt_model_profile -m mt_model_profile -t template_profile' % sys.argv[0]) sys.exit() elif opt in (" ", ""): print( '%s -w wt_model_profile -m mt_model_profile -t template_profile' % sys.argv[0]) sys.exit() elif opt in ("-w", "--wprofile"): wp = arg elif opt in ("-m", "--mprofile"): mp = arg elif opt in ("-t", "--tprofile"): tp = arg pic_out = mp.replace("profile", "png") e = modeller.environ() a = modeller.alignment(e, file=mp.replace("profile", "ali")) template = get_profile(tp, a['6Y2HA']) wmodel = get_profile(mp, a['CLIC5']) mmodel = get_profile(wp, a['CLIC5']) # Plot the template and model profiles in the same plot for comparison: pylab.figure(1, figsize=(10, 6)) pylab.xlabel('Alignment position') pylab.ylabel('DOPE per-residue score') pylab.plot(template, color='red', linewidth=2, label='Template') pylab.plot(wmodel, color='green', linewidth=2, label='Wt multi-template Model') pylab.plot(mmodel, color='black', linewidth=2, label='Mt multi-template Model') pylab.legend() pylab.savefig(pic_out, dpi=65)
def test_script1(self): """Test step 1 (build profile)""" # Make sure the script runs without errors p = subprocess.check_call(['scripts/script1_build_profile.py']) # Make sure the profile contains the sequences we expect e = modeller.environ() a = modeller.alignment(e, file='output/build_profile.ali') self.assertEqual(sorted(s.code for s in a), sorted(self.templates) + ['P0A6F5']) os.unlink('output/build_profile.prf') os.unlink('output/build_profile.ali')
def get_environ(self): """Set up the Modeller environment, and keep a reference to it so that we only need to do it once for all tests""" if not self._env: env = modeller.environ() env.io.atom_files_directory = ['../data', 'test/data'] env.edat.dynamic_sphere = False env.libs.topology.read(file='${LIB}/top_heav.lib') env.libs.parameters.read(file='${LIB}/par.lib') ModellerTest._env = env return self._env
def main(): rsr_file, pdb_file, sclbreak, opts = parse_args() e = modeller.environ() e.io.hetatm = True a = ChargedContactFinder(e, rsr_file, pdb_file) a.find() a.print_contacts(open('contpres.dat', 'w')) if opts.cdensity_cutoff is not None: a.print_cdensity(opts.cdensity_cutoff, sclbreak, open('break.dat', 'a')) else: a.print_all_buried(sclbreak, open('break.dat', 'a'))
def main(): import modeller file1, file2, rcut = parse_args() e = modeller.environ() e.io.hetatm = True mdl1 = modeller.model(e, file=file1) mdl2 = modeller.model(e, file=file2) for ri, rj, dist in get_inter_contacts(e, mdl1, mdl2, rcut): print(" %6s %2s %6s %2s %3s %3s%3d%11.3f %1d %1d" % (ri.num, ri.chain.name, rj.num, rj.chain.name, ri.pdb_name, rj.pdb_name, get_contact_type(ri, rj), dist, 6, 6))
def modeller_automodel(self, query: SeqRecord, results: Path, num_align: int, atom_files_dir: Path): from modeller import environ from modeller.automodel import automodel for model_index, r in enumerate( np.load(results, allow_pickle=True)[:num_align]): try: aln = AlignIO.read(StringIO(r[-2][0]), 'clustal') except: logging.error( f'Failed to parse alignment: {r[0]} -> {r[2]} -> {r[4]} -> {r[6]}' ) continue assert query.id == aln[0].id and aln[-1].id == r[-3] q_rec, t_rec = self._remove_gaps(aln[0], aln[-1]) try: t_rec = self._remove_missing_res( t_rec, (atom_files_dir / aln[-1].id[2:4] / f'{aln[-1].id}.ent').resolve().as_posix()) except FileNotFoundError as e: logging.exception(e) continue q_rec.name, t_rec.name = '', '' q_rec.description = f'sequence:{q_rec.id}::::::::' t_rec.description = f'structureX:{t_rec.id}::{t_rec.id[-2].upper()}::{t_rec.id[-2].upper()}::::' aln = MultipleSeqAlignment([q_rec, t_rec]) out_d = results.resolve().parent if (out_d / f'{aln[0].id}_{model_index+1}.pdb').exists(): continue cwd = os.getcwd() with tempfile.TemporaryDirectory() as tmpdir: try: os.chdir(tmpdir) AlignIO.write(aln, 'aln.pir', 'pir') env = environ() env.io.atom_files_directory = [ (atom_files_dir / aln[1].id[2:4]).resolve().as_posix() ] mod = automodel(env, 'aln.pir', knowns=[aln[1].id], sequence=aln[0].id) mod.make() shutil.copy( list(Path().glob('*.B*.pdb'))[0], out_d / f'{aln[0].id}_{model_index+1}.pdb') except Exception as e: logging.error( f'knowns=[{aln[1].id}], sequence={aln[0].id}') logging.exception(e) finally: os.chdir(cwd)
def main(): pdb1, ligand, pdb2, rcut, opts = parse_args() e = modeller.environ() e.io.hetatm = True a = AllostericSiteFinder(e, pdb1, ligand, pdb2, rcut) try: if opts.output_pdb: a.find().write(file=opts.output_pdb) if opts.atom_list: a.write_atom_list(open(opts.atom_list, 'w')) except AllostericSiteError as err: print(str(err), file=sys.stderr) sys.exit(1)
def process_modpipe_profiles(): # https://salilab.org/modbase-download/projects/genomes/M_tuberculosis/2018/m_tuberculosis_2018.tar # https://salilab.org/modbase-download/projects/genomes/L_major/2016/l_major_2016.tar # https://salilab.org/modbase-download/modbase_models_academic-20120928.txt.gz # https://salilab.org/modeller/supplemental.html # https://salilab.org/modeller/downloads/20200513_pdb95.pir.gz # https://salilab.org/modeller/downloads/20200513_pdb95_profiles.tar.bz2 -> data/i8/1i8oA env = environ() # /mnt/data/data/databases/pdb/modpipe/data/i8/1i8oA prf = profile(env, file="./1i8oA-uniprot90.prf", profile_format="TEXT") aln = prf.to_alignment() aln.write(file='pepe.fasta', alignment_format='FASTA')
def __init__(self): self.tmpdir = TMP_BASE_DIR + "/mod" + str(uuid.uuid4()) #self.tmpdir = "/tmp/modtest" self.ch_id = '' self.sequences = None self.templ_file = 'templ.pdb' try: os.mkdir(self.tmpdir) except IOError as err: sys.exit(err) self.env = environ() self.env.io.atom_files_directory = [self.tmpdir] log.none()
def count_alignments(aln_file, target, templates): import modeller modeller.log.none() env = modeller.environ() aln = modeller.alignment(env, file=aln_file) target = aln[target] templates = [aln[t] for t in templates] num_align = 0 for r in target.residues: for template in templates: if r.get_aligned_residue(template) is not None: num_align += 1 return num_align, len(target.residues)
def test_setup_atoms(self): """Test setup_atoms()""" import modeller from allosmod.edit_restraints import RestraintEditor, Sigmas sigmas = allosmod.edit_restraints.Sigmas(1, 1.0, 2.0, 3.0) with open('atomlistASRS', 'w') as fh: for i in range(64): fh.write("%d %s\n" % (i+1, "AS" if i < 10 else "RS")) with open('break.dat', 'w') as fh: fh.write('1 20') env = modeller.environ() env.io.hetatm = True e = RestraintEditor('test.rsr', 'test.rsr', os.path.join(test_dir, 'input', 'test_editrsr.pdb'), ['test.pdb'], 'atomlistASRS', sigmas, 10.0, 0.1, 'break.dat', False, False) class Residue(object): pass def mock_get_cont(fname, rcut): ri = Residue() ri.index = 1 rj = Residue() rj.index = 4 yield ri, rj, 10.0 def mock_get_ss(pdb_file): return [] with utils.mock_method(allosmod.get_contacts, 'get_contacts', mock_get_cont): with utils.mock_method(allosmod.get_ss, 'get_ss', mock_get_ss): e.setup_atoms(env) contacts = sorted(e.contacts.keys()) # Should have the 1-4 interaction from get_contacts, plus the two # nucleic acids (#6 and #7) should interact with everything self.assertEqual(contacts, [(1, 4), (1, 6), (1, 7), (2, 6), (2, 7), (3, 6), (3, 7), (4, 6), (4, 7), (5, 6), (5, 7), (6, 6), (6, 7), (7, 7)]) self.assertEqual(e.breaks, {1: 20.0}) # First 10 atoms should be allosteric site self.assertEqual([a.isAS for a in e.atoms], [True]*10 + [False]*54) # One CA and CB for each residue self.assertEqual(len([a for a in e.atoms if a.isCA]), 4) self.assertEqual(len([a for a in e.atoms if a.isCB]), 4) self.assertTrue(e.atoms[1].isCA) self.assertTrue(e.atoms[2].isCB) self.assertEqual(len([a for a in e.atoms if a.isSC]), 5) self.assertTrue(e.atoms[3].isSC) self.assertEqual(len([a for a in e.atoms if a.isNUC]), 39) self.assertEqual(len([a for a in e.atoms if a.torestr]), 18) os.unlink('break.dat') os.unlink('atomlistASRS')
def _structureX_seq_from_modeller(self): """ return a str containing the first two lines of the sequence corresponding to structureX a file named [self._id]_structureX.seq also written """ env = modeller.environ() model = modeller.model(env, file=self._id) aln = modeller.alignment(env) aln.append_model(model, align_codes=self._id) out_file = self._id + "_structureX.seq" aln.write(file=out_file) out_str = open(out_file, "r").read() out_str = [c for c in out_str.split("\n") if c] out_str = "\n".join(out_str[:2]) + "\n*" return out_str
def get_auto_align(in_aln_file, target, templates, out_aln_file): import modeller modeller.log.none() env = modeller.environ() env.io.atom_files_directory = ['.'] aln = modeller.alignment(env, file=in_aln_file, align_codes=target) with allosmod.util.temporary_directory() as tempd: temp_aln = os.path.join(tempd, "templates.ali") with open(temp_aln, 'w') as fh: for template in templates: pdb2ali(template, fh=fh) aln.append(file=temp_aln) aln.salign(overhang=30, gap_penalties_1d=(-450, -50), alignment_type='tree', output='ALIGNMENT') aln.write(file=out_aln_file)
def test_script3(self): """Test step 3 (density segmentation)""" # Make sure the script runs without errors p = subprocess.check_call(['scripts/script3_density_segmentation.py']) # Should have produced a PDB with coordinates of all 14 subunit centers e = modeller.environ() m = modeller.model(e, file='output/groel_segments_center.pdb') self.assertEqual(len(m.atoms), 14) self.assertEqual(len(m.residues), 14) # load_configuration file should load all 14 subunits, and set level wc = len(open('output/load_configuration.cmd').readlines()) self.assertEqual(wc, 15) os.unlink('output/load_configuration.cmd') os.unlink('output/groel_segments_center.pdb') for i in range(14): os.unlink('output/groel_subunit_%d.mrc' % i)
def main(): import modeller (listoth_rsr, listas_rs, pdb_file, contacts_pdbs, atomlist_asrs, opts) = parse_args() sigmas = Sigmas(opts.ntotal, opts.sig_AS, opts.sig_RS, opts.sig_inter) modeller.log.none() env = modeller.environ() env.io.hetatm = True e = RestraintEditor(listoth_rsr, listas_rs, pdb_file, allosmod.util.read_templates(contacts_pdbs), atomlist_asrs, sigmas, opts.cutoff, opts.delEmax, opts.break_file, opts.coarse, opts.locrigid) e.edit(env)
def test_get_target(self): """Test get_target function""" from allosmod.get_pm_initialstruct import get_target with open('test.aln', 'w') as fh: fh.write("""C; Sample alignment >P1;1fdx sequence:1fdx.pdb:1 : :54 : ::: 2.00:-1.00 AFVV* >P1;5fd1 structureX:5fd1.pdb:1 :A:106 :A::: 1.90: 0.19 AFVV* """) e = modeller.environ() self.assertEqual(get_target(e, 'foo', 'test.aln'), 'foo') self.assertEqual(get_target(e, None, 'test.aln'), '1fdx') os.unlink('test.aln')
def plot_profiles(aln_file, template_profile, template_code, model_profile, model_code): e = modeller.environ() a = modeller.alignment(e, file=aln_file) template = get_profile(template_profile, a[template_code]) model = get_profile(model_profile, a[model_code]) # Plot the template and model profiles in the same plot for comparison: pylab.figure(1, figsize=(10, 6)) pylab.xlabel('Alignment position') pylab.ylabel('DOPE per-residue score') pylab.plot(model, color='red', linewidth=2, label=model_code) pylab.plot(template, color='green', linewidth=2, label=template_code) pylab.legend() pylab.savefig('dope_profile_best_model.png', dpi=65)
def test_detect_invalid_residue_types_bad(self): """Test _detect_invalid_residue_types() with bad sequence""" with utils.temporary_directory() as tmpdir: fname = os.path.join(tmpdir, 'test.pdb') with open(fname, 'w') as fh: fh.write(""" ATOM 1 N CYS A 1 18.511 -1.416 15.632 1.00 6.84 C ATOM 2 C CYS A 1 18.511 -1.416 15.632 1.00 6.84 C ATOM 3 N HIE A 2 18.511 -1.416 15.632 1.00 6.84 C ATOM 4 C HIE A 2 18.511 -1.416 15.632 1.00 6.84 C ATOM 5 N HSD B 3 18.511 -1.416 15.632 1.00 6.84 C ATOM 6 C HSD B 3 18.511 -1.416 15.632 1.00 6.84 C """) e = modeller.environ() m = modeller.model(e, file=fname) self.assertRaises(cleaning.InvalidResiduesError, cleaning._detect_invalid_residue_types, m)
def run_modeller(target, template, model_dir, model_pdbfilepath, model_pdbfilepath_uncompressed, template_structure_dir, aln_filepath='alignment.pir', write_modeller_restraints_file=False): modeller.log.none() env = modeller.environ() env.io.atom_files_directory = [template_structure_dir] a = modeller.automodel.allhmodel( env, alnfile=aln_filepath, knowns=template.id, sequence=target.id ) a.make() # do homology modeling save_modeller_output_files(target, model_dir, a, env, model_pdbfilepath, model_pdbfilepath_uncompressed, write_modeller_restraints_file=write_modeller_restraints_file)
def optimize(pdb, pdb_path): print(1, pdb_path) # Environ data env = environ(0) env.io.atom_files_directory = ['../atom_files'] env.edat.dynamic_sphere = True env.libs.topology.read(file='$(LIB)/top_heav.lib') env.libs.parameters.read(file='$(LIB)/par.lib') code = pdb.split('.')[0] mdl = complete_pdb(env, pdb) mdl.write(file=code+'.ini') # Select all atoms: atmsel = selection(mdl) # Generate the restraints: mdl.restraints.make(atmsel, restraint_type='stereo', spline_on_site=False) mdl.restraints.write(file=code+'.rsr') mpdf_prior = atmsel.energy() # Create optimizer objects and set defaults for all further optimizations cg = conjugate_gradients(output='REPORT') md = molecular_dynamics(output='REPORT') # Open a file to get basic stats on each optimization trcfil = open(code+'.D00000001', 'w') # Run CG on the all-atom selection; write stats every 5 steps cg.optimize(atmsel, max_iterations=20, actions=actions.trace(5, trcfil)) # Run MD; write out a PDB structure (called '1fas.D9999xxxx.pdb') every # 10 steps during the run, and write stats every 10 steps md.optimize(atmsel, temperature=300, max_iterations=50, actions=[actions.write_structure(10, code+'.D9999%04d.pdb'), actions.trace(10, trcfil)]) # Finish off with some more CG, and write stats every 5 steps cg.optimize(atmsel, max_iterations=20, actions=[actions.trace(5, trcfil)]) mpdf_after = atmsel.energy() mdl.write(file=os.path.join(pdb_path, 'optimized.pdb')) return (mpdf_prior, mpdf_after)
def get_q_ca(target, templates, rcut): import modeller modeller.log.none() e = modeller.environ() e.io.hetatm = False m = modeller.model(e) coord = get_coordinates(m, target) dist = get_distances(coord) q_tot = [] q_cut = [] for template in templates: t, c = get_qi_ca(m, len(coord), dist, template, rcut) q_tot.append(t) q_cut.append(c) write_q_scores(q_tot, open('qscore1to%d.dat' % len(coord), 'w')) write_q_scores(q_cut, open('qs_cut1to%d.dat' % len(coord), 'w'))
def test_simple(self): """Simple complete run of get_pm_initialstruct""" from allosmod.get_pm_initialstruct import get_pm_initialstruct with utils.temporary_directory() as tmpdir: self.setup_inputs(tmpdir) check_output(['allosmod', 'get_pm_initialstruct', '--target', 'foo', '--keep-alignment', 'test.aln', 'templates', '.', '1', 'slow'], cwd=tmpdir) e = modeller.environ() m = modeller.model(e, file=os.path.join(tmpdir, 'pred_1fdx', 'foo.B99990001.pdb')) self.assertEqual([x.code for x in m.residues], ['A', 'W']) self.assertEqual(m.chains[0].name, 'A') for f in ('1fdx', 'foo.B99990001.pdb', 'foo.ini', 'foo.sch', 'test.aln', 'foo.D00000001', 'foo.rsr', 'foo.V99990001'): os.unlink(os.path.join(tmpdir, 'pred_1fdx', f))
def test_simple(self): """Simple complete run of make_mod_inputs""" with allosmod.util.temporary_directory() as tempdir: self.setup_inputs(dir=tempdir) check_output(['allosmod', 'make_mod_inputs', '--', '1fdx', 'templates', '-3333', '3', '3', '3', '4'], cwd=tempdir) e = modeller.environ() for fname in ('random.ini', '1fdx.ini'): m = modeller.model(e, file=os.path.join(tempdir, fname)) self.assertEqual([x.code for x in m.residues], ['A', 'Y']) # Should have converted CA-only in all-atom model self.assertEqual(len(m.atoms), 18) with open(os.path.join(tempdir, '1fdx.rsr')) as fh: self.assertEqual(len(fh.readlines()), 78) for f in ('templates', 'avgpdb.pdb', '5fd1', 'align.ali', 'random.ini', '1fdx.ini', '1fdx.rsr'): os.unlink(os.path.join(tempdir, f))
def model3D(fic, ALLPDB, pdb_extension='.cif'): if _MODELLER_MESSAGE != "": raise ImportError(_MODELLER_MESSAGE) seqs = readFastaMul(fic) if len(seqs) < 2: raise Exception("There aren't template sequences in %s." % fic) seq = seqs[0][0].split('\n')[0] seq = seq.split(';')[1] modeller.log.verbose() # request verbose output env = modeller.environ() # create a new MODELLER environment to build ... # ... this model in env.io.atom_files_directory = ['.'] # ['.', ALLPDB] knowns = [] for i in range(1, len(seqs)): tmp = seqs[i][0].split('\n')[0] tmp = tmp.split(';')[1] knowns.append(tmp) kn = tmp.split('_')[0].lower() # upper ? base_name = kn + pdb_extension nam = base_name # + '.gz' if not os.path.isfile(kn + pdb_extension): # shutil.copyfile(ALLPDB + nam, "./" + nam) shutil.copy2(os.path.join(ALLPDB, nam), nam) # # os.system("gunzip ./" + nam) # with gzip.open(nam, 'rb') as f_in: # with open(base_name, 'wb') as f_out: # shutil.copyfileobj(f_in, f_out) # splitChainsPDB('pdb' + kn + pdb_extension, kn, 'pdb') knowns = tuple(knowns) a = automodel.automodel(env, alnfile=fic, knowns=knowns, sequence=seq) a.max_molpdf = 1e12 a.starting_model = 1 # index of the first model a.ending_model = 1 # index of the last model # (determines how many models to calculate) cdir = os.getcwd() print("cdir = ", cdir) a.make() # do the actual homology modeling return 1
def test_modeller_restraints(self): """Check using Modeller restraints in IMP""" e = modeller.environ() e.edat.dynamic_sphere = False e.libs.topology.read("${LIB}/top_heav.lib") e.libs.parameters.read("${LIB}/par.lib") modmodel = modeller.model(e) modmodel.build_sequence("GGCC") feat = modeller.features.distance(modmodel.atoms[0], modmodel.atoms[-1]) r = modeller.forms.gaussian(feature=feat, mean=10.0, stdev=1.0, group=modeller.physical.xy_distance) modmodel.restraints.add(r) m = IMP.kernel.Model() protein = IMP.modeller.ModelLoader(modmodel).load_atoms(m) atoms = IMP.atom.get_by_type(protein, IMP.atom.ATOM_TYPE) m.add_restraint(IMP.modeller.ModellerRestraints(m, modmodel, atoms)) assertSimilarModellerIMPScores(self, modmodel, protein) self.assertAlmostEqual(m.evaluate(False), 5.7837, delta=1e-3)
def main(): if len(sys.argv) != 2: print 'ERROR, incorrect number of inputs!!!' print usage quit() elif not osp.isfile(sys.argv[1]): print 'The input file' + sys.argv[1] + ' does not exist!!!' print usage quit() env = environ() env.libs.topology.read(file='$(LIB)/top_heav.lib') env.libs.parameters.read(file='$(LIB)/par.lib') mdl = complete_pdb(env, sys.argv[1]) atmsel = selection(mdl.chains[0]) score = atmsel.assess_dope() return 0
def soap_score(): import modeller from modeller.scripts import complete_pdb from modeller import soap_protein_od env = modeller.environ() env.libs.topology.read(file='$(LIB)/top_heav.lib') env.libs.parameters.read(file='$(LIB)/par.lib') # Set up SOAP-Protein-OD scoring (we create the scorer once and keep it # around, since reading in the potential from disk can take a long time). sp = soap_protein_od.Scorer() out = open('SnapList.txt', 'w') cnt = 0 files = [ i for i in glob.glob('pm.pdb*.pdb') if 'pm.pdb.B10010002.pdb' not in i ] for fil in files: try: cnt += 1 # Read a model previously generated by Modeller's automodel class mdl = complete_pdb(env, fil) # Select all atoms atmsel = modeller.selection(mdl) # Assess with the above Scorer try: score = atmsel.assess(sp) out.write(fil + '\t' + str(score) + '\n') except modeller.ModellerError: print("The SOAP-Protein-OD library file is not included " "with MODELLER.") print("Please get it from https://salilab.org/SOAP/.") # Was 'except: pass' but this will hide genuine errors. Replace with # a more specific list of exceptions (and test) except: raise out.close()
def test_imp_restraints(self): """Check using IMP restraints in Modeller""" e = modeller.environ() e.edat.dynamic_sphere = False e.libs.topology.read('${LIB}/top_heav.lib') e.libs.parameters.read('${LIB}/par.lib') modmodel = modeller.model(e) modmodel.build_sequence('GGCC') m = IMP.Model() protein = IMP.modeller.ModelLoader(modmodel).load_atoms(m) atoms = IMP.atom.get_by_type(protein, IMP.atom.ATOM_TYPE) r = IMP.core.DistanceRestraint(m, IMP.core.Harmonic(10.0, 1.0), atoms[0], atoms[-1]) sf = IMP.core.RestraintsScoringFunction([r]) t = modmodel.env.edat.energy_terms t.append(IMP.modeller.IMPRestraints(atoms, sf)) assertSimilarModellerIMPScores(self, sf, modmodel, protein) self.assertAlmostEqual(sf.evaluate(False), 9.80, delta=1e-2)