Exemple #1
0
def test_lprmsd_5(get_fn):
    t = md.load(get_fn('frame0.h5'))
    t1 = md.load(get_fn('frame0.h5'))

    r = md.rmsd(t, t1, 0)
    a = md.lprmsd(t, t1, 0, permute_groups=[[]], superpose=True)
    eq(a, r, decimal=3)
Exemple #2
0
def test_lprmsd_3(get_fn):
    # resolve rotation and permutation togetehr
    t1 = md.load(get_fn('alanine-dipeptide-explicit.pdb'))[0]
    t2 = md.load(get_fn('alanine-dipeptide-explicit.pdb'))[0]

    h2o_o_indices = [a.index for a in t1.topology.atoms if a.residue.name == 'HOH' and a.element.symbol == 'O'][0:20]
    h2o_h_indices = [a.index for a in t1.topology.atoms if a.residue.name == 'HOH' and a.element.symbol == 'H'][0:20]
    backbone_indices = [a.index for a in t1.topology.atoms if a.element.symbol in ['C', 'N']][:5]

    # scramble two groups of indices
    t2.xyz[:, random.permutation(h2o_o_indices)] = t2.xyz[:, h2o_o_indices]
    t2.xyz[:, random.permutation(h2o_h_indices)] = t2.xyz[:, h2o_h_indices]

    # offset the backbone indices slightly
    t2.xyz[:, backbone_indices] += 0.001 * random.randn(len(backbone_indices), 3)

    # rotate everything
    rot = rotation_matrix_from_quaternion(uniform_quaternion())
    t2.xyz[0].dot(rot)

    print('raw distinguishable indices', backbone_indices)
    atom_indices = np.concatenate((h2o_o_indices, backbone_indices))
    value = md.lprmsd(t2, t1, atom_indices=atom_indices, permute_groups=[h2o_o_indices])
    t1.xyz[:, h2o_o_indices] += random.randn(len(h2o_o_indices), 3)

    print('final value', value)
    assert value[0] < 1e-2
Exemple #3
0
def test_lprmsd_1():
    # resolve a random rotation with no permutation
    ref = random.randn(1, 50, 3).astype(np.float32)
    mapping = np.arange(50)
    rot = rotation_matrix_from_quaternion(uniform_quaternion())
    new = ref[:, mapping].dot(rot)

    value = lprmsd(Trajectory(xyz=new, topology=None), Trajectory(xyz=ref, topology=None), permute_groups=[[]])
    assert value[0] < 1e-2
Exemple #4
0
def test_lprmsd_0():
    # remap a permutation of all the atoms with no rotation
    ref = random.randn(1, 10, 3).astype(np.float32)
    mapping = random.permutation(10)
    print('true mapping', mapping)
    new = ref[:, mapping]

    value = lprmsd(Trajectory(xyz=new, topology=None), Trajectory(xyz=ref, topology=None))
    eq(value, np.array([0.0], dtype=np.float32), decimal=3)
Exemple #5
0
def test_lprmsd_2():
    # resolve a random rotation with some permutation
    ref = random.randn(1, 50, 3).astype(np.float32)
    # first half of the atoms can permute, last 10 are fixed permutation
    mapping = np.concatenate((random.permutation(10), 10 + np.arange(40)))
    rot = rotation_matrix_from_quaternion(uniform_quaternion())
    new = ref[:, mapping].dot(rot)
    
    value = lprmsd(Trajectory(xyz=new, topology=None), Trajectory(xyz=ref, topology=None), permute_groups=[np.arange(10)])
    assert value[0] < 1e-2
Exemple #6
0
def main():
    rstr = args.ref
    ref = mdtraj.load(rstr)
    fn = args.zf
    pth = '/'.join(fn.split('/')[:-1])

    # extract zip file
    xtract(fn)

    # easier to move into working dir
    os.chdir(pth)

    # set some final params
    od = './relevant/'
    try:
        os.mkdir(od)
    except OSError:
        pass
    rf = 'receptor.pdb'
    ligf = 'lig.pdb'

    og_pdbs = [f for f in os.listdir('.') if '.pdb' in f]
    # pull clc config from lig 0
    call_write('grep -v LIG ' + og_pdbs[0], rf)
    # rewrite to dock dir in consistent format
    recptr = mdtraj.load(rf)
    recptr.save_pdb(od + rf)

    # parse ligs out of dock pdbs
    for p, pdb in enumerate(og_pdbs):
        call_write('grep LIG ' + pdb, 'lig_' + str(p) + '.pdb')
    # get updated list of lig pdbs
    lig_pdbs = [f for f in os.listdir('.') if 'lig_' in f]
    lig_pdbs.sort()

    # join lig pdbs into one trj
    lig_trj = mdtraj.load(lig_pdbs[0])
    for lig in lig_pdbs[1:]:
        l = mdtraj.load(lig)
        lig_trj += l

    # compare distances of ligand pdbs to reference
    dists = mdtraj.lprmsd(lig_trj, ref)
    # get closest 3
    winnars = np.argsort(dists)[:3]

    # move receptor and closest lig to dock dir
    for w in winnars:
        lig_trj[w].save_pdb(od + str(w) + '_' + ligf)

    # write some reference info
    results = open('results.dat', 'w+')
    results.write('path: ' + pth + '\n')
    results.write('ref: ' + rstr + '\n')
    results.write('w1nn4r: ' + str(winnars) + '\n')
Exemple #7
0
def test_lprmsd_4(get_fn):
    t1 = md.load(get_fn('1bpi.pdb'))
    t1.xyz += 0.05 * random.randn(t1.n_frames, t1.n_atoms, 3)
    t2 = md.load(get_fn('1bpi.pdb'))
    # some random indices
    indices = random.permutation(t1.n_atoms)[:t1.n_atoms - 5]

    got = md.lprmsd(t2, t1, atom_indices=indices, permute_groups=[[]])
    ref = md.rmsd(t2, t1, atom_indices=indices)

    eq(got, ref, decimal=3)
def test_lprmsd_null():
    ref = random.randn(1, 10, 3).astype(np.float32)
    new = np.copy(ref)

    value = lprmsd(Trajectory(xyz=new, topology=None), Trajectory(xyz=ref, topology=None))
    eq(value, np.array([0.0], dtype=np.float32), decimal=3)