def Optimizemodel(pdb_file): """ This functions returns a file with the optimized model from the input pdb. It also returns the energies. """ env = environ() 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, ext = pdb_file.split('.') mdl = complete_pdb(env, pdb_file) mdl.write(file=code + '.ini') # Select all atoms: atmsel = selection(mdl) mpdf2 = atmsel.energy() # Generate the restraints: #mdl.restraints.make(atmsel, restraint_type='improper', spline_on_site=False) #mdl.restraints.make(atmsel, restraint_type='bond', spline_on_site=False) #mdl.restraints.make(atmsel, restraint_type='sphere', spline_on_site=False) mdl.restraints.make(atmsel, restraint_type='stereo', spline_on_site=False) mdl.restraints.write(file=code + '.rsr') mpdf1 = 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) ]) #refine(atmsel, code, 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 = atmsel.energy() print("The initial energy of " + code + " is " + str(mpdf1[0])) print("The final energy of " + code + " is " + str(mpdf[0])) print("The final energy of " + code + " is " + str(mpdf2[0])) mdl.write(file=code + '_optimized.pdb')
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 refine(atmsel, code, trcfil): # at T=1000, max_atom_shift for 4fs is cca 0.15 A. md = molecular_dynamics(cap_atom_shift=0.39, md_time_step=4.0, md_return='FINAL') init_vel = True for (its, equil, temps) in ((200, 20, (150.0, 250.0, 400.0, 700.0, 1000.0)), (200, 600, (1000.0, 800.0, 600.0, 500.0, 400.0, 300.0))): for temp in temps: md.optimize(atmsel, init_velocities=init_vel, temperature=temp, max_iterations=its, equilibrate=equil, actions=[ actions.write_structure(10, code + '.D9999%04d.pdb'), actions.trace(10, trcfil) ]) init_vel = False
# 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 = 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 = file(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 = atmsel.energy() mdl.write(file=code+'.B')
dih_lib_only=True) mdl.restraints.make(all_atoms, aln=aln, restraint_type='PHI_DIHEDRAL',spline_on_site=True, dih_lib_only=True) mdl.restraints.make(all_atoms, aln=aln, restraint_type='PSI_DIHEDRAL',spline_on_site=True, dih_lib_only=True) mdl.restraints.condense() # energy data env.edat.dynamic_lennard = True # Prepare optimizer scaling_factors = physical.values(default=1.0, em_density=0) MD = molecular_dynamics(output='REPORT',cap_atom_shift=0.0001, md_time_step=0.05,temperature=params.temperature, init_velocities=True,md_return=params.md_return, equilibrate = params.equilibrate, schedule_scale=scaling_factors) w=actions.write_structure(params.skip_its_for_writing, 'md-%03d.pdb', write_all_atoms=True, first=True, last=True, start=0) # optimize MD.optimize(all_atoms, max_iterations=params.max_iterations,actions=[w]) for c in mdl.chains: c.name = 'A' mdl.remark ="" mdl.reorder_atoms() mdl.write(params.output_pdb_file, model_format='PDB')
# Open a file to get basic stats on each optimization trcfil = file(query_id + '.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), min_atom_shift=0.01) # 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, query_id + '.D9998%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 = atmsel.energy() mdl.write(file=query_id + '.D00000001.pdb') contacts = parse_contacts.parse(open(contact_filename, 'r')) count = 0 seq_len = len(aln[query_id]) for (score, i, j) in contacts: rsr.add( forms.gaussian(group=physical.xy_distance,
def Optimizemodel(pdb_file): """ It creates a PDB file with the optimized model from the input pdb, with its energies and restraint contributions. Also it will create pdbs on every step of the Molecular Dynamics optimization. The energy is returned as the total value of Modeller's objective function, molpdf. It also shows the topt 10 contributors to the molpdf before and after optimization """ # Setting up env = environ() 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, ext = pdb_file.split('.') # Complete the pdb and make a model mdl = complete_pdb(env, pdb_file) mdl.write(file=code + '.ini') # Select all atoms from the model, make restraints and save them in a file atmsel = selection(mdl) mdl.restraints.make(atmsel, restraint_type='stereo', spline_on_site=False) mdl.restraints.write(file=code + '.rsr') # Check the energy before optimization and save it in a var initial_mpdf = atmsel.energy() # Create optimizer objects cg = conjugate_gradients(output='REPORT') md = molecular_dynamics(output='REPORT') # Open a file to get basic stats on each optimization stats_file = open(code + '_opt.stats', 'w') # Run MD. Write out a PDB structure every 10 steps during the run. # Write stats every 10 steps md.optimize(atmsel, temperature=300, max_iterations=50, actions=[ actions.write_structure(10, code + '.MD%04d.pdb'), actions.trace(10, stats_file) ]) # Run CG, and write stats every 5 steps cg.optimize(atmsel, max_iterations=50, actions=[actions.trace(5, stats_file)]) # Final energy final_mpdf = atmsel.energy() # Assess DOPE atmsel.assess_dope(output='ENERGY_PROFILE NO_REPORT', file='TvLDH.profile', normalize_profile=True, smoothing_window=15) # Print the energies and the contributions initial_cont_all = dict(initial_mpdf[1]) top_init_conts = dict( sorted(initial_cont_all.items(), key=itemgetter(1), reverse=True)[:5]) l.info("\n\nThe initial energy of " + code + " is " + str(initial_mpdf[0])) print("\n\nThe initial energy of " + code + " is " + str(initial_mpdf[0])) print("The top 10 initial contributions the restraints are:\n") for keys, values in top_init_conts.items(): print(keys, ":", values) final_cont_all = dict(final_mpdf[1]) top_final_conts = dict( sorted(final_cont_all.items(), key=itemgetter(1), reverse=True)[:5]) l.info("\n\nThe final energy of " + code + " is " + str(final_mpdf[0])) print("\n\nThe final energy of " + code + " is " + str(final_mpdf[0])) print("Final contributions the restraints are:\n") for keys, values in top_final_conts.items(): print(keys, ":", values) mdl.write(file=code + '_optimized.pdb')
def optimization(pdb_file, options): """This function needs as an input a PDB file (the model), and gives as an output the optimized model.""" env = environ() 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') path, ext = pdb_file.split('.') list = path.split('/') #if results/4g83/4g83model.pdb list[0]=results list[1]=4g83 list[2]=4g83model dir = list[0] + "/" + list[1] code = list[2] mdl = complete_pdb(env, pdb_file) mdl.write(file=path + '.ini') atmsel = selection(mdl) mpdf_ini = atmsel.energy() z_score_ini = mdl.assess_normalized_dope() mdl_ep_ini = atmsel.get_dope_profile() mdl_ep_ini_smoothed = mdl_ep_ini.get_smoothed() energy_profile_txt_path = dir + '/' + code + '_DOPE_EnergyProfile.txt' mdl_ep_ini_smoothed.write_to_file(energy_profile_txt_path) print("The unoptimized model's energy of " + code + " is: " + str(mpdf_ini[0])) print("The unoptimized Z-score of " + code + " is: " + str(z_score_ini)) energy_profile_txt_path_opt = None if options.optimize: cg = conjugate_gradients(output='REPORT') md = molecular_dynamics(output='REPORT') trcfil = open(path + '.D00000001', 'w') cg.optimize(atmsel, max_iterations=20, actions=actions.trace(5, trcfil)) md.optimize(atmsel, temperature=300, max_iterations=50, actions=[ actions.write_structure(10, path + '.D9999%04d.pdb'), actions.trace(10, trcfil) ]) cg.optimize(atmsel, max_iterations=20, actions=[actions.trace(5, trcfil)]) mpdf = atmsel.energy() z_score = mdl.assess_normalized_dope() print("The final model energy of " + path + " is " + str(mpdf[0])) print("The final model energy of " + path + " is " + str(mpdf_ini[0])) print("The final z-score of " + code + " is: " + str(z_score)) mdl.write(file=path + '_optimized.pdb') mdl_final = atmsel.get_dope_profile() mdl_final_smoothed = mdl_final.get_smoothed(window=50) energy_profile_txt_path_opt = dir + '/' + code + '_optimized_DOPE_EnergyProfile.txt' mdl_final_smoothed.write_to_file(energy_profile_txt_path_opt) mdl.write(file=dir + '/' + code + '_optimized.pdb') energy_profile_plot(options, dir, code, energy_profile_txt_path, energy_profile_txt_path_opt)