コード例 #1
0
    def test_circular(self):
        u = mda.Universe.empty(6, trajectory=True)
        # circular structure
        bondlist = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 0)]
        u.add_TopologyAttr(Bonds(bondlist))

        with pytest.raises(ValueError) as ex:
            polymer.sort_backbone(u.atoms)
        assert 'cyclical' in str(ex.value)
コード例 #2
0
    def test_sortbb(self, u):
        # grab backbone atoms out of order
        # 0 1 4 6 8 - correct
        ag = u.atoms[[4, 1, 0, 8, 6]]

        s_ag = polymer.sort_backbone(ag)

        assert_equal(s_ag.ids, [0, 1, 4, 6, 8])
コード例 #3
0
    def test_branches(self, u):
        # includes side branches, can't sort
        bad_ag = u.atoms[:10]  # include -H etc

        with pytest.raises(ValueError):
            polymer.sort_backbone(bad_ag)
コード例 #4
0
 def test_not_fragment(self, u):
     # two fragments don't work
     bad_ag = u.residues[0].atoms[:2] + u.residues[1].atoms[:2]
     with pytest.raises(ValueError):
         polymer.sort_backbone(bad_ag)
コード例 #5
0
    def test_missing_bonds(self):
        u = mda.Universe(Plength)

        with pytest.raises(NoDataError):
            polymer.sort_backbone(u.atoms[:10])
コード例 #6
0
ファイル: analysis.py プロジェクト: EqualAPriori/SCOUTff
def PersistenceL(trajFile,
                 top,
                 backboneAtoms,
                 NP,
                 coef=1. / 10.,
                 stride=1.,
                 chain0Id=0,
                 firstpoint=2):
    """
    get persistence length of chains of indices from chain0Id to chain0Id+NP-1 
    coef: divide results by 10. to convert to nm since MDAnalysis uses Angstrom
"""
    from MDAnalysis.lib.mdamath import make_whole
    import MDAnalysis as mda
    from MDAnalysis.analysis import polymer

    u = mda.Universe(top, trajFile)
    for frag in u.atoms.fragments:
        make_whole(frag)
    molecules = u.atoms.fragments
    filter = 'name {}'.format(*backboneAtoms)
    backbones = [mol.select_atoms(filter)
                 for mol in molecules][chain0Id:chain0Id + NP]
    sorted_backbones = [polymer.sort_backbone(bb) for bb in backbones]

    persistence_length = polymer.PersistenceLength(sorted_backbones)
    persistence_length.run()
    LB = persistence_length.lb * coef
    if firstpoint == 0:
        LP = persistence_length.lp * coef
    else:
        LP = polymer.fit_exponential_decay(
            persistence_length.x[firstpoint:],
            persistence_length.results[firstpoint:])
        persistence_length.fit = np.exp(-persistence_length.x[firstpoint:] /
                                        LP)
        LP *= coef

    fig, ax = plt.subplots(nrows=1, ncols=1, figsize=[3, 2])
    ax.plot(persistence_length.x * coef,
            persistence_length.results,
            'ro',
            label='Result')
    ax.plot(persistence_length.x[firstpoint:] * coef,
            persistence_length.fit,
            label='Fit')
    ax.vlines(LP, 0., 1, ls=':', lw=0.75)
    plt.text(2. * LP,
             0.5 * max(persistence_length.fit),
             '$<cos\\theta> = exp(-n*{}/{})$'.format(round(LB, 3),
                                                     round(LP, 3)),
             size=7)
    ax.set_xlim(-0.1, 1.1 * max(persistence_length.x * coef))
    ax.set_xlabel(r'$n*l_b$')
    ax.set_ylabel(r'$C(n*l_b)$')
    plt.savefig('persistenceL.png',
                dpi=500,
                transparent=True,
                bbox_inches="tight")

    return LP, LB, len(sorted_backbones[0])