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)
Esempio n. 2
0
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_normal_pdb():
    fn = get_fn('4lzt/4lzt.not_les.pdb')
    tn = get_fn('4lzt/4lzt.parm7')
    rst7 = get_fn('4lzt/4lzt.rst7')

    pdb_input = pdb.input(fn)
    symm = pdb_input.crystal_symmetry()
    pdb_hc = pdb_input.construct_hierarchy()

    phenix_coords_uc = expand_coord_to_unit_cell(pdb_hc.atoms().extract_xyz(),
                                                 symm)

    indices_dict = get_indices_convert_dict(fn)
    p2a_indices = indices_dict['p2a']
    a2p_indices = indices_dict['a2p']
    parm = pmd.load_file(tn, rst7)

    a0 = reorder_coords_phenix_to_amber(phenix_coords_uc, p2a_indices)

    # make sure phenix and amber read the same coordinates
    aa_eq(pdb_input.atoms().extract_xyz(), parm.coordinates, decimal=2)
    aa_eq(a0, parm.coordinates, decimal=2)

    # make sure the a2p_indices and p2a_indices are identical for non-LES
    indices_dict = get_indices_convert_dict_from_array(
        pdb_input.atoms().extract_xyz(), parm.coordinates)
    p2a_indices = indices_dict['p2a']
    a2p_indices = indices_dict['a2p']
    eq(a2p_indices, p2a_indices)
def test_sander_struct():
    fn = get_fn('4lzt_pawel/4lztabH.pdb')
    tn = get_fn('4lzt_pawel/4lztab.parm7')
    rst7 = get_fn('4lzt_pawel/4lztabH.rst7')
    s_struct = SanderStruct(tn, rst7)
    parm = pmd.load_file(tn, rst7)
    aa_eq(parm.coordinates, s_struct.parm.coordinates)
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_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_converter_by_array():
    fn = get_fn('4lzt_pawel/4lztabH.pdb')
    tn = get_fn('4lzt_pawel/4lztab.parm7')
    rst7 = get_fn('4lzt_pawel/4lztabH.rst7')

    pdb_input = pdb.input(fn)
    parm = pmd.load_file(tn, rst7)

    symm = pdb_input.crystal_symmetry()

    # reorder
    pdb_hc = pdb_input.construct_hierarchy()

    phenix_coords_uc = expand_coord_to_unit_cell(pdb_hc.atoms().extract_xyz(),
                                                 symm)

    indices_dict = get_indices_convert_dict_from_array(phenix_coords_uc,
                                                       parm.coordinates)
    p2a_indices = indices_dict['p2a']
    a2p_indices = indices_dict['a2p']

    a0 = reorder_coords_phenix_to_amber(phenix_coords_uc, p2a_indices)

    # make sure the original pdb and rst7 have the same coordinates
    aa_eq(pdb_input.atoms().extract_xyz(), parm.coordinates, decimal=2)

    # make sure reordered coordinates is equal to original coordinates
    aa_eq(a0, parm.coordinates, decimal=2)

    # raise KeyError if provide wrong coordinates
    def make_sure_key_error_being_raised():
        phenix_coords = flex.vec3_double([
            [0., 2., 3.2],  # should be [0., 2., 3.]
            [4., 5., 6.],
            [10., 12., 13.],
            [7., 8., 9.]
        ])
        amber_coords = np.array([[10., 12., 13.], [7., 8., 9], [4., 5., 6.],
                                 [0., 2., 3.]])
        get_indices_convert_dict_from_array(phenix_coords, amber_coords)

    with pytest.raises(KeyError):
        make_sure_key_error_being_raised()
Esempio n. 9
0
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_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_converter():
    fn = get_fn('4lzt_pawel/4lztabH.pdb')
    tn = get_fn('4lzt_pawel/4lztab.parm7')
    rst7 = get_fn('4lzt_pawel/4lztabH.rst7')

    pdb_input = pdb.input(fn)
    parm = pmd.load_file(tn, rst7)

    symm = pdb_input.crystal_symmetry()
    pdb_hc = pdb_input.construct_hierarchy()

    phenix_coords_uc = expand_coord_to_unit_cell(pdb_hc.atoms().extract_xyz(),
                                                 symm)

    indices_dict = get_indices_convert_dict(fn)
    p2a_indices = indices_dict['p2a']
    a2p_indices = indices_dict['a2p']
    # make sure two indices are not equal
    with pytest.raises(AssertionError):
        aa_eq(p2a_indices, a2p_indices)

    a0 = reorder_coords_phenix_to_amber(phenix_coords_uc, p2a_indices)
    aa_eq(pdb_input.atoms().extract_xyz(), parm.coordinates)
    aa_eq(a0, parm.coordinates)
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_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_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
Esempio n. 15
0
#!/usr/bin/env phenix.python
import subprocess
import pytest
from numpy.testing import assert_almost_equal as aa_eq
from amber_adaptbx.tests.utils import (
    tempfolder,
    get_fn,
    get_energy_and_forces,
    get_prmtop_and_rst7_and_pdb_filenames_from_pdb,
)
import sander
import parmed as pmd


@pytest.mark.parametrize('pdb_file', [get_fn('2igd/2igd_simplified.pdb')])
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)
import subprocess
import pytest
import libtbx.load_env
from amber_adaptbx.tests.utils import (
    tempfolder,
    get_fn,
    assert_energy_and_forces,
    run_sander_minimization,
    get_prmtop_and_rst7_and_pdb_filenames_from_pdb,
)


@pytest.mark.slow
@pytest.mark.minimization
@pytest.mark.parametrize('pdb_file', [
    get_fn('2igd/2igd.pdb'),
    get_fn('4lzt/4lzt_no_BHOH.pdb'),
    get_fn('4lzt/4lzt.pdb'),
])
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',
Esempio n. 17
0
  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'


@pytest.mark.parametrize('pdb_file', [
    get_fn('2g3i/2g3i.pdb'),
])
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 = [