def test_cleaning_unused_files(code): pdb_fn = get_fn('{code}/{code}.pdb'.format(code=code)) command_non_les = ['phenix.AmberPrep', pdb_fn, 'LES=False'] expected_files_non_les = set([ '4phenix_{}.pdb'.format(code), '4amber_{}.prmtop'.format(code), '4amber_{}.rst7'.format(code), ]) command_les = ['phenix.AmberPrep', pdb_fn, 'LES=True'] expected_files_les = set() expected_files_les.update(expected_files_non_les) expected_files_les.update( set([ '4phenix_{}.pdb'.format(code), '4amber_{}.prmtop'.format(code), '4amber_{}.rst7'.format(code), '4amber_{}.LES.pdb'.format(code), 'addles.in', ])) with tempfolder(): subprocess.check_call(command_les) file_set = set(glob('*')) assert sorted(expected_files_les) == sorted(file_set) with tempfolder(): subprocess.check_call(command_non_les) file_set = set(glob('*')) assert sorted(expected_files_non_les) == sorted(file_set)
def test_writing_HOH(code): # not WAT pdb_fn = get_fn('{code}/{code}.pdb'.format(code=code)) command_les = [ 'phenix.AmberPrep', pdb_fn, ] output_pdb = '4phenix_{}.pdb'.format(code) output_les_pdb = '4phenix_{}.pdb'.format(code) # LES = False with tempfolder(): subprocess.check_call(command_les + [ 'LES=False', ]) parm = pmd.load_file(output_pdb) assert 'HOH' in set(residue.name for residue in parm.residues) assert 'WAT' not in set(residue.name for residue in parm.residues) # LES = True with tempfolder(): subprocess.check_call(command_les + ['LES=True']) parm = pmd.load_file(output_pdb) parm_les = pmd.load_file(output_les_pdb) assert 'HOH' in set(residue.name for residue in parm_les.residues) assert 'WAT' not in set(residue.name for residue in parm_les.residues)
def test_ensure_amber_and_phenix_have_the_same_atom_order_in_pdb_output(): command_refine_template = [ 'phenix.refine', '4phenix_2igd.pdb', get_fn('2igd/2igd.mtz'), 'topology_file_name=4amber_2igd.prmtop', 'coordinate_file_name=4amber_2igd.rst7', 'wxc_scale=0.025', '--overwrite', ] command_build = [ 'phenix.AmberPrep', get_fn('2igd/2igd.pdb'), ] command_refine_use_amber = command_refine_template[:] command_refine_use_amber.append('use_amber=True') command_refine_use_phenix = command_refine_template[:] command_refine_use_phenix.append('use_amber=False') print(command_refine_use_amber) print(command_refine_use_phenix) pdb_fn = '4phenix_2igd_refine_001.pdb' with tempfolder(): subprocess.check_call(command_build) subprocess.check_call(command_refine_use_amber) amber_parm = pmd.load_file(pdb_fn) with tempfolder(): subprocess.check_call(command_build) subprocess.check_call(command_refine_use_phenix) phenix_parm = pmd.load_file(pdb_fn) for atom_amber, atom_phenix in zip(amber_parm.atoms, phenix_parm.atoms): assert atom_amber.name == atom_phenix.name
def test_bfactor_occupancy_by_comparing_pdb_files(code): pdb_fn = get_fn('fake/{}.pdb'.format(code)) # 3-name rules, there is no ".LES.' in final pdb anymore. final_pdb_fn = '4phenix_{}.pdb'.format(code) les_pdb = '4phenix_{}.LES.pdb'.format(code) parm_expected_pdb_non_les = pmd.load_file( get_fn('fake/{}'.format(final_pdb_fn))) parm_expected_pdb_les = pmd.load_file(get_fn('fake/{}'.format(les_pdb))) command_build = [ 'phenix.AmberPrep', pdb_fn, 'use_amber_unitcell=False', ] # 'LES=False' with tempfolder(): subprocess.check_call(command_build + [ 'LES=False', ]) parm_non_les = pmd.load_file(final_pdb_fn) subprocess.check_call(command_build + [ 'LES=True', ]) parm_les = pmd.load_file(final_pdb_fn) equal_bfactor_and_occupancy(parm_non_les, parm_expected_pdb_non_les) equal_bfactor_and_occupancy(parm_les, parm_expected_pdb_les)
def test_netcdf_trajectory(): command_refine = [ 'phenix.refine', get_fn('vAla3/vAla3.pdb'), get_fn('vAla3/vAla3.cif'), get_fn('vAla3/vAla3.mtz'), 'topology_file_name={}'.format(get_fn('vAla3/vAla3.prmtop')), 'coordinate_file_name={}'.format(get_fn('vAla3/vAla3.rst7')), 'use_amber=True', 'wxc_scale=0.025', '--overwrite', 'refinement.main.number_of_macro_cycles=1', 'amber.netcdf_trajectory_file_name=hello.nc' ] n_frames = 59 parm = pmd.load_file(get_fn('vAla3/vAla3.prmtop')) expected_boxes = np.array(n_frames * [ [30., 30., 30., 90., 90., 90.], ], dtype='f8') with tempfolder(): output = subprocess.check_output(command_refine) traj = NetCDFTraj.open_old('hello.nc') print(traj.coordinates.shape) aa_eq(traj.box, expected_boxes) assert traj.coordinates.shape == (n_frames, len(parm.atoms), 3)
def test_refinement_after_running_AmberPrep_use_amber_True_from_DAC_script( pdb_file, mtz_file): """ just ensure no error. There is no assertion here """ command_build = ['phenix.AmberPrep', pdb_file, 'LES=True'] prmtop_file, rst7_file, new_pdb_file = get_prmtop_and_rst7_and_pdb_filenames_from_pdb( pdb_file, LES=True) use_amber = True command_refine = [ 'phenix.refine', new_pdb_file, mtz_file, 'topology_file_name={}'.format(prmtop_file), 'amber.coordinate_file_name={}'.format(rst7_file), 'use_amber={}'.format(use_amber), 'refinement.target_weights.optimize_xyz_weight=False', 'strategy=individual_sites+individual_adp', 'prefix=amber', 'serial=1', 'write_geo=False', 'refinement.main.number_of_macro_cycles=10', ] # below command is not from Dave's script # Why adding? because got error: No array of R-free flags found. # phenix suggested: refinement.input.xray_data.r_free_flags.generate=True # TODO command_refine.append( 'refinement.input.xray_data.r_free_flags.generate=True') with tempfolder(): subprocess.check_call(command_build) subprocess.check_call(command_refine)
def test_non_LES_refinement_vAla3(use_amber): command_refine = [ 'phenix.refine', get_fn('vAla3/vAla3.pdb'), get_fn('vAla3/vAla3.cif'), get_fn('vAla3/vAla3.mtz'), 'topology_file_name={}'.format(get_fn('vAla3/vAla3.prmtop')), 'coordinate_file_name={}'.format(get_fn('vAla3/vAla3.rst7')), 'use_amber={}'.format(use_amber), 'wxc_scale=0.025', '--overwrite', 'refinement.main.number_of_macro_cycles=1' ] expected_r = { # 'Start R-work': 0.0154, 'Start R-free': 0.0154, 'Final R-work': 0.0066, 'Final R-free': 0.0065 } with tempfolder(): output = subprocess.check_output(command_refine) for line in output.split('\n'): if 'Final R-work' in line: break final_r_work = float(line.split()[3].strip(',')) final_r_free = float(line.split()[6]) aa_eq([ final_r_work, ], [ expected_r['Final R-work'], ], decimal=3) aa_eq([ final_r_free, ], [ expected_r['Final R-free'], ], decimal=3)
def test_refinement_phenix(pdb_file, mtz_file): """ ensure there is no error, there is no assertion """ print(('pdb_file', pdb_file)) prmtop_file, rst7_file, new_pdb_file = get_prmtop_and_rst7_and_pdb_filenames_from_pdb( pdb_file) command_build = [ 'phenix.AmberPrep', '{pdb_file}'.format(pdb_file=pdb_file) ] command_refine = [ 'phenix.refine', '{pdb_file}'.format(pdb_file=new_pdb_file), '{mtz_file}'.format(mtz_file=mtz_file), 'amber.topology_file_name={}'.format(prmtop_file), 'amber.coordinate_file_name={}'.format(rst7_file), 'refinement.main.number_of_macro_cycles=2', ] if '4lzt' in pdb_file: command_refine.append( 'refinement.input.xray_data.r_free_flags.generate=True') with tempfolder(): subprocess.check_output(command_build) print(' '.join(command_refine)) # subprocess.check_output(command_refine) subprocess.call(command_refine)
def test_geometry_minimization_from_AmberPrep_with_amber_all_option(pdb_file): """ ensure there is no error, there is no assertion """ command = "phenix.AmberPrep {} LES=True minimise=amber_all minimization_options='maxcyc=2'".format( pdb_file) with tempfolder(): prmtop_file, rst7_file, new_pdb_file = get_prmtop_and_rst7_and_pdb_filenames_from_pdb( pdb_file) subprocess.check_output(command.split())
def test_build_from_pdb_that_does_not_have_remark_290(pdb_file): command_build = [ 'phenix.AmberPrep', pdb_file, 'use_amber_unitcell=False', ] with tempfolder(): # just make sure no error subprocess.check_call(command_build)
def test_command_line_build(pdb_file): command = 'phenix.AmberPrep {} LES=True'.format(pdb_file) prmtop_file, rst7_file, _ = get_prmtop_and_rst7_and_pdb_filenames_from_pdb( pdb_file) with tempfolder(): subprocess.check_output(command.split()) # ensure not error output = run_sander_minimization( prmtop_file=prmtop_file, rst7_file=rst7_file) assert 'FINAL RESULTS' in output
def test_adding_addles_option_to_command_line(): addles_input = get_fn('2igd/addles_test/addles.in') addles_input_wrong_header = get_fn( '2igd/addles_test/addles.wrong_header.in') pdb_fn = get_fn('2igd/2igd.pdb') prmtop = '4amber_2igd.prmtop' command_build_addles_input_cmd = [ 'phenix.AmberPrep', pdb_fn, 'LES=True', 'addles_input={}'.format(addles_input) ] with tempfolder(): subprocess.check_call(command_build_addles_input_cmd) parm = pmd.load_file(prmtop) assert len(parm.atoms) == 5148 command_build_normal = [ 'phenix.AmberPrep', pdb_fn, 'LES=True', ] with tempfolder(): subprocess.check_call(command_build_normal) parm = pmd.load_file(prmtop) assert len(parm.atoms) == 5240 command_build_wrong_header = [ 'phenix.AmberPrep', pdb_fn, 'LES=True', 'addles_input={}'.format(addles_input_wrong_header) ] with tempfolder(): with pytest.raises(subprocess.CalledProcessError): subprocess.check_call(command_build_wrong_header) command_build_non_existing_file = [ 'phenix.AmberPrep', pdb_fn, 'LES=True', 'addles_input={}'.format('some_weird_random_name_you_are_not_lucky.in') ] with tempfolder(): with pytest.raises(subprocess.CalledProcessError): subprocess.check_call(command_build_non_existing_file)
def test_run_sander_LES_minimization_from_LES_build(pdb_file): """ ensure we can run minimization, maxcyc=10 Tests for 2igd.pdb, 4lzt_no_BHOH.pdb """ with tempfolder(): command = 'phenix.AmberPrep {pdb_file} LES=True'.format( pdb_file=pdb_file) # run building LES prmtop subprocess.check_call(command.split()) prmtop_file, rst7_file, _ = get_prmtop_and_rst7_and_pdb_filenames_from_pdb( pdb_file, LES=True) output = run_sander_minimization( prmtop_file=prmtop_file, rst7_file=rst7_file, maxcyc=10) assert 'FINAL RESULTS' in output, 'minimization must be finished'
def test_HOH_occupancy(code): # H in HOH must have the same occupancy with O (HOH) pdb_fn = get_fn('{code}/{code}.pdb'.format(code=code)) command_les = [ 'phenix.AmberPrep', pdb_fn, ] output_pdb = '4phenix_{}.pdb'.format(code) with tempfolder(): subprocess.check_call(command_les + [ 'LES=False', ]) parm = pmd.load_file(output_pdb) subprocess.check_call(command_les + [ 'LES=True', ]) parm_les = pmd.load_file(output_pdb) wat_residues_les = [ residue for residue in parm_les.residues if residue.name[:3] == 'HOH' ] wat_residues = [ residue for residue in parm.residues if residue.name[:3] == 'HOH' ] for residue in wat_residues_les: # all atoms in residue should have the same occupancy assert len(set(atom.occupancy for atom in residue.atoms)) == 1 for residue in wat_residues: # all atoms in residue should have the same occupancy assert len(set(atom.occupancy for atom in residue.atoms)) == 1 if code in [ '1gdu', ]: # having some O (HOH) with occupancy < 1.0 occupancy_set = set( atom.occupancy for atom in itertools.chain.from_iterable(wat_residues_les)) assert len(occupancy_set - set([ 0.75, 1.0, 0.74, 0.94, 0.5, 0.88, 0.73, ])) > 0
def test_LES_refinement_from_saved_2igd_files(prmtop_file, rst7_file, pdb_file, mtz_file, use_amber): """ just ensure no error. There is no assertion here """ command_list = [ 'phenix.refine', pdb_file, mtz_file, 'topology_file_name={}'.format(prmtop_file), 'amber.coordinate_file_name={}'.format(rst7_file), 'use_amber={}'.format(use_amber), 'strategy=individual_sites+individual_adp+occupancies', 'write_geo=False', 'refinement.main.number_of_macro_cycles=2', ] with tempfolder(): subprocess.call(command_list)
def test_geometry_minimization_from_AmberPrep_with_amber_all_option_with_assertion_and_larger_maxcyc( pdb_file): """ ensure there is no error, there is no assertion """ command = [ "phenix.AmberPrep", pdb_file, "LES=True", "minimise=amber_all", "minimization_options='maxcyc=2'", "clean=off", ] with tempfolder(): prmtop_file, rst7_file, new_pdb_file = get_prmtop_and_rst7_and_pdb_filenames_from_pdb( pdb_file) subprocess.check_output(command) assert (os.path.exists( get_minimized_pdb_filename( pdb_file, minimization_type='amber_all', LES=True)))
def test_geometry_minimization(pdb_file): """ """ command_build = 'phenix.AmberPrep {}'.format(pdb_file) with tempfolder(): prmtop_file, rst7_file, new_pdb = get_prmtop_and_rst7_and_pdb_filenames_from_pdb( pdb_file) output = subprocess.check_output(command_build, shell=True) command_list = [ 'phenix.geometry_minimization', new_pdb, 'use_amber=True', 'amber.topology_file_name={}'.format(prmtop_file), 'amber.coordinate_file_name={}'.format(rst7_file), ] print(('geometry_minimization command: ', ' '.join(command_list))) output = subprocess.check_output(command_list) assert 'Write PDB file' in output assert '_minimized.pdb' in output
def test_writing_example_after_running_AmberPrep_LES_without_minimization(): pdb_file = get_fn('2igd/2igd.pdb') LES = True expected_line = """ ================================================== Done. Three new files have been made: 4phenix_2igd.pdb 4amber_2igd.prmtop 4amber_2igd.rst7 ================================================== """ # always create new command_build command_build = [ 'phenix.AmberPrep', pdb_file, 'LES={}'.format(LES), ] with tempfolder(): output_build = subprocess.check_output(command_build) assert expected_line in output_build
def test_minus_0_coordinates_use_amber_all_for_minimise(pdb_file): """ ensure there is no error if having -0.0 coordinates """ command_build = [ 'phenix.AmberPrep', pdb_file, 'LES=True', 'minimise=amber_all', "minimization_options='maxcyc=10'" ] amber_minimimized_pdb = get_minimized_pdb_filename( pdb_file, LES=True, minimization_type='amber_all') prmtop, _, _ = get_prmtop_and_rst7_and_pdb_filenames_from_pdb( pdb_file, LES=True) minimized_rst7 = get_minimized_rst7_filename( pdb_file, minimization_type='amber_all', LES=True) command_geom = [ 'phenix.geometry_minimization', amber_minimimized_pdb, 'amber.topology_file_name', prmtop, 'amber.coordinate_file_name', minimized_rst7 ] with tempfolder(): subprocess.check_call(command_build) # use geometry_minimization to trigger computing reorder map subprocess.check_call(command_geom)
def test_writing_example_after_running_AmberPrep_LES_with_minimization( minimization_type): pdb_file = get_fn('2igd/2igd.pdb') LES = True expected_line_dict = { 'amber_h': """ ================================================== Done. Three new files have been made: 4phenix_2igd.pdb 4amber_2igd.prmtop 4amber_2igd.rst7 ================================================== """, 'amber_all': """ ================================================== Done. Three new files have been made: 4phenix_2igd.pdb 4amber_2igd.prmtop 4amber_2igd.rst7 ================================================== """, } # always create new command_build command_build = [ 'phenix.AmberPrep', pdb_file, 'LES={}'.format(LES), ] with tempfolder(): command_build.append('minimise={}'.format(minimization_type)) if minimization_type in ['amber_all', 'amber_h']: command_build.append('minimization_options="maxcyc=2"') else: command_build.append('minimization_options="max_iterations=2"') output_build = subprocess.check_output(command_build) assert expected_line_dict[minimization_type] in output_build
def test_non_LES_refinement_after_running_AmberPrep_use_amber_True_and_do_minimization_with_amber_h( pdb_file, mtz_file): """ just ensure no error. There is no assertion here """ LES = False command_build = [ 'phenix.AmberPrep', pdb_file, 'LES={}'.format(LES), 'minimise=amber_h', 'minimization_options="maxcyc=2"', ] prmtop_file, _, _ = get_prmtop_and_rst7_and_pdb_filenames_from_pdb( pdb_file, LES=LES) use_amber = True minimized_rst7_file = get_minimized_rst7_filename( pdb_file, minimization_type='amber_h', LES=LES) minimized_pdb_file = get_minimized_pdb_filename( pdb_file, minimization_type='amber_h', LES=LES) command_refine = [ 'phenix.refine', minimized_pdb_file, mtz_file, 'topology_file_name={}'.format(prmtop_file), 'amber.coordinate_file_name={}'.format(minimized_rst7_file), 'use_amber={}'.format(use_amber), 'strategy=individual_sites+individual_adp+occupancies', 'write_geo=False', 'refinement.main.number_of_macro_cycles=2', 'refinement.input.xray_data.r_free_flags.generate=True', ] with tempfolder(): subprocess.check_call(command_build) subprocess.check_call(command_refine)
def test_LES_refinement_after_running_AmberPrep_use_amber_True_but_not_doing_minimization( pdb_file, mtz_file): """ just ensure no error. There is no assertion here """ command_build = ['phenix.AmberPrep', pdb_file, 'LES=True'] prmtop_file, rst7_file, new_pdb_file = get_prmtop_and_rst7_and_pdb_filenames_from_pdb( pdb_file) use_amber = True command_refine = [ 'phenix.refine', new_pdb_file, mtz_file, 'topology_file_name={}'.format(prmtop_file), 'amber.coordinate_file_name={}'.format(rst7_file), 'use_amber={}'.format(use_amber), 'strategy=individual_sites+individual_adp+occupancies', 'write_geo=False', 'refinement.main.number_of_macro_cycles=2', 'refinement.input.xray_data.r_free_flags.generate=True', ] with tempfolder(): subprocess.check_call(command_build) subprocess.check_call(command_refine)
def test_geometry_minimization_from_AmberPrep_with_amber_h_option(pdb_file): """ ensure there is no error, there is no assertion """ command = "phenix.AmberPrep {} LES=True minimise=amber_h minimization_options='maxcyc=2'".format( pdb_file) with tempfolder(): subprocess.check_output(command.split())
def test_geometry_minimization_command_line_with_amber_h_option(pdb_file): """ ensure there is no error, there is no assertion """ command = 'phenix.AmberPrep {} minimise=amber_h'.format(pdb_file) with tempfolder(): subprocess.check_output(command.split())
def test_run_sander_LES_minimization_from_saved_files(prmtop_file, rst7_file): """ ensure we can run minimization """ with tempfolder(): output = run_sander_minimization( prmtop_file=prmtop_file, rst7_file=rst7_file, maxcyc=10) assert 'FINAL RESULTS' in output