def run(project, atom_indices=None, traj_fn = 'all'):

    n_atoms = project.load_conf()['XYZList'].shape[1]

    if traj_fn.lower() == 'all':

        SASA = np.ones((project.n_trajs, np.max(project.traj_lengths), n_atoms)) * -1

        for traj_ind in xrange(project.n_trajs):
            traj_asa = []
            logger.info("Working on Trajectory %d", traj_ind)
            traj_fn = project.traj_filename(traj_ind)
            chunk_ind = 0
            for traj_chunk in Trajectory.enum_chunks_from_lhdf( traj_fn, AtomIndices=atom_indices ):
                #print chunk_ind
                traj_asa.extend(asa.calculate_asa(traj_chunk, n_sphere_points = 24))
                chunk_ind += 1
            SASA[traj_ind, 0:project.traj_lengths[traj_ind]] = traj_asa

    else:
        traj_asa = []
        for traj_chunk in Trajectory.enum_chunks_from_lhdf( traj_fn, AtomIndices=atom_indices ):
            traj_asa.extend( asa.calculate_asa( traj_chunk ) )

        SASA = np.array(traj_asa)

    return SASA
def run(project, atom_indices=None, traj_fn='all'):

    n_atoms = project.load_conf()['XYZList'].shape[1]

    if traj_fn.lower() == 'all':

        SASA = np.ones(
            (project.n_trajs, np.max(project.traj_lengths), n_atoms)) * -1

        for traj_ind in xrange(project.n_trajs):
            traj_asa = []
            logger.info("Working on Trajectory %d", traj_ind)
            traj_fn = project.traj_filename(traj_ind)
            chunk_ind = 0
            for traj_chunk in Trajectory.enum_chunks_from_lhdf(
                    traj_fn, AtomIndices=atom_indices):
                #print chunk_ind
                traj_asa.extend(
                    asa.calculate_asa(traj_chunk, n_sphere_points=24))
                chunk_ind += 1
            SASA[traj_ind, 0:project.traj_lengths[traj_ind]] = traj_asa

    else:
        traj_asa = []
        for traj_chunk in Trajectory.enum_chunks_from_lhdf(
                traj_fn, AtomIndices=atom_indices):
            traj_asa.extend(asa.calculate_asa(traj_chunk))

        SASA = np.array(traj_asa)

    return SASA
Example #3
0
def test_asa_2():
    t = Trajectory.load_trajectory_file(os.path.join(fixtures_dir(), 'trj0.lh5'))
    val1 = np.sum(calculate_asa(t[0])) # calculate only frame 0
    val2 = np.sum(calculate_asa(t)[0]) # calculate on all frames
    true_frame_0_asa = 2.859646797180176
    
    npt.assert_approx_equal(true_frame_0_asa, val1)
    npt.assert_approx_equal(true_frame_0_asa, val2)
Example #4
0
def test_asa_2():
    t = get("Trajectories/trj0.lh5")
    val1 = np.sum(calculate_asa(t[0]))  # calculate only frame 0
    val2 = np.sum(calculate_asa(t)[0])  # calculate on all frames
    true_frame_0_asa = 2.859646797180176

    assert_approx_equal(true_frame_0_asa, val1)
    assert_approx_equal(true_frame_0_asa, val2)
Example #5
0
def test_asa_0():
    # make one atom at the origin
    traj = {"XYZList": np.zeros((1, 1, 3)), "AtomNames": ["H"]}

    probe_radius = 0.14
    calc_area = np.sum(calculate_asa(traj, probe_radius=probe_radius))
    true_area = 4 * np.pi * (ATOMIC_RADII["H"] + probe_radius) ** 2

    assert_approx_equal(calc_area, true_area)
Example #6
0
def test_asa_0():    
    # make one atom at the origin
    traj = {'XYZList': np.zeros((1,1,3)),
            'AtomNames': ['H']}
            
    probe_radius = 0.14
    calc_area = np.sum(calculate_asa(traj, probe_radius=probe_radius))
    true_area = 4 * np.pi * (ATOMIC_RADII['H'] + probe_radius)**2

    npt.assert_approx_equal(calc_area, true_area)
Example #7
0
def test_asa_3():
    traj_ref = get("g_sas_ref.dat")
    traj = get("Trajectories/trj0.lh5")
    traj_asa = calculate_asa(traj, probe_radius=0.14, n_sphere_points=960)

    # the algorithm used by gromacs' g_sas is slightly different than the one
    # used here, so the results are not exactly the same -- see the comments
    # in src/python/geomtry/asa.py or the readme file src/ext/asa/README.txt
    # for details
    assert_array_almost_equal(traj_asa, traj_ref, decimal=2)
Example #8
0
def test_asa_3():

    traj_ref = np.loadtxt( os.path.join(reference_dir(),'g_sas_ref.dat'))
    Conf = Trajectory.load_from_pdb(os.path.join( fixtures_dir(), 'native.pdb'))

    traj = Trajectory.load_trajectory_file( os.path.join(fixtures_dir(), 'trj0.xtc') , Conf=Conf)
    traj_asa = calculate_asa(traj, probe_radius=0.14, n_sphere_points = 960)
    
    # the algorithm used by gromacs' g_sas is slightly different than the one
    # used here, so the results are not exactly the same -- see the comments
    # in src/python/geomtry/asa.py or the readme file src/ext/asa/README.txt
    # for details
    npt.assert_array_almost_equal(traj_asa, traj_ref, decimal=2)    
Example #9
0
def test_asa_1():
    # two atoms
    traj = {"XYZList": np.zeros((1, 2, 3)), "AtomNames": ["H", "H"]}

    probe_radius = 0.14
    true = 4 * np.pi * (ATOMIC_RADII["H"] + probe_radius) ** 2

    # when atoms are closer than 2e-5, there seems to be a bug.
    # note that you should never actually have a case where atoms are this close
    # but nonetheless I'm adding a check for this in the implementation -- to make
    # it crash if the atoms are too close, as opposed to giving you wrong results
    separations = np.linspace(2.0e-5, probe_radius * 2 + ATOMIC_RADII["H"] * 2, 10)
    areas = np.zeros_like(separations)

    # check the asa as we vary the separation
    for i, sep in enumerate(separations):
        traj["XYZList"][0, 0, 1] = sep
        areas[i] = np.sum(calculate_asa(traj, probe_radius=probe_radius))

    assert_approx_equal(areas[0], true)
    assert_approx_equal(areas[-1], 2 * true)
    # make sure that areas is increasing
    assert_array_less(areas[0:8], areas[1:9])
Example #10
0
def test_asa_1():
    # two atoms
    traj = {'XYZList': np.zeros((1,2,3)),
            'AtomNames': ['H', 'H']}

    probe_radius = 0.14
    true  = 4 * np.pi * (ATOMIC_RADII['H'] + probe_radius)**2

    # when atoms are closer than 2e-5, there seems to be a bug.
    # note that you should never actually have a case where atoms are this close
    # but nonetheless I'm adding a check for this in the implementation -- to make
    # it crash if the atoms are too close, as opposed to giving you wrong results
    separations = np.linspace(2.0e-5, probe_radius*2 + ATOMIC_RADII['H']*2, 10)
    areas = np.zeros_like(separations)

    # check the asa as we vary the separation
    for i, sep in enumerate(separations):
        traj['XYZList'][0, 0, 1] = sep
        areas[i] = np.sum(calculate_asa(traj, probe_radius=probe_radius))
    
    npt.assert_approx_equal(areas[0], true)
    npt.assert_approx_equal(areas[-1], 2*true)
    # make sure that areas is increasing
    npt.assert_array_less(areas[0:8], areas[1:9])
Example #11
0
from msmbuilder.geometry import asa
from msmbuilder import Trajectory
from msmbuilder import io
import numpy as np

p=Trajectory.load_from_pdb('barstarH.pdb')

sasa = asa.calculate_asa(p, n_sphere_points=150)

io.saveh('sasa.h5', sasa=sasa)