Ejemplo n.º 1
0
    def RDF(self, type1, type2):
        import MDAnalysis
        import MDAnalysis.analysis.rdf
        import matplotlib.pyplot as plt
        # import matplotlib as plt

        import os

        os.chdir(self.dire)
        print(os.getcwd())
        u = MDAnalysis.Universe('XDATCAR.pdb', permissive=True)
        g1 = u.select_atoms(type1)
        g2 = u.select_atoms(type2)
        rdf = MDAnalysis.analysis.rdf.InterRDF(
            g1, g2, nbins=75, range=(0.0, min(u.dimensions[:3]) / 2.0))

        rdf.run()

        fig = plt.figure(figsize=(5, 4))
        ax = fig.add_subplot(111)
        ax.plot(rdf.bins, rdf.rdf, 'g-', label="rdf")
        font1 = {
            'family': 'Times New Roman',
            'weight': 'bold',
        }
        ax.legend(frameon=True, edgecolor='none', facecolor='none', prop=font1)
        ax.set_xlabel(r"Distance ($\AA$)")
        ax.set_ylabel(r"RDF")
        fig.savefig("RDF_all.png",
                    bbox_inches='tight',
                    transparent=True,
                    dpi=600,
                    format='png')
        plt.show()
Ejemplo n.º 2
0
def plot_traj_rdf(trajs, labels, ax):
    '''Plot the RDF'''

    for t, l in zip(trajs, labels):
        u = MDAnalysis.Universe(t)
        g = u.select_atoms('name O')
        rdf = MDAnalysis.analysis.rdf.InterRDF(g, g)
        rdf.run()
        print(rdf.rdf)
        ax.plot(rdf.bins, rdf.rdf, label=l)

    ax.legend(loc='best')
    ax.set_xlabel('$r$ [Å]')
    ax.set_ylabel('$g(r)$')
    plt.tight_layout()
Ejemplo n.º 3
0
def test_double_run(sels):
    # running rdf twice should give the same result
    s1, s2 = sels
    rdf = InterRDF(s1, s2).run()
    rdf.run()
    assert len(rdf.count[rdf.count == 3]) == 7
Ejemplo n.º 4
0
import MDAnalysis
import MDAnalysis.analysis.rdf
import matplotlib.pyplot as plt

u = MDAnalysis.Universe('XDATCAR.pdb', permissive=True)
g1 = u.select_atoms('type O')
g2 = u.select_atoms('type H')
rdf = MDAnalysis.analysis.rdf.InterRDF(g1,
                                       g2,
                                       nbins=75,
                                       range=(0.0,
                                              min(u.dimensions[:3]) / 2.0))

rdf.run()

fig = plt.figure(figsize=(5, 4))
ax = fig.add_subplot(111)
ax.plot(rdf.bins, rdf.rdf, 'k-', label="rdf")

ax.legend(loc="best")
ax.set_xlabel(r"Distance ($\AA$)")
ax.set_ylabel(r"RDF")
fig.savefig("RDF_all.png")
#plt.show()
Ejemplo n.º 5
0
    def POSTAIMD(
        self,
        filename,
        rdf_fir,
        rdf_sec,
    ):

        from ase.io import read, write
        import os
        import MDAnalysis
        import MDAnalysis.analysis.rdf
        import MDAnalysis.analysis.rms
        import matplotlib.pyplot as plt
        import pandas as pd

        os.chdir(self.dire)
        # write('traj.pdb', read(filename))

        u = MDAnalysis.Universe(filename, permissive=True)
        u.dimensions = [73, 73, 73, 90, 90, 90]
        u.atoms.write("traj.pdb", frames='all')
        u.atoms.write("crystal.xyz")
        g1 = u.select_atoms(rdf_fir)
        g2 = u.select_atoms(rdf_sec)
        rdf = MDAnalysis.analysis.rdf.InterRDF(
            g1, g2, nbins=75, range=(0.0, min(u.dimensions[:3]) / 2.0))

        rdf.run()
        fig = plt.figure(figsize=(5, 4))
        ax = fig.add_subplot(111)
        ax.plot(rdf.bins, rdf.rdf, 'k-', label="rdf")
        ax.legend(loc="best")
        ax.set_xlabel(r"Distance ($\AA$)")
        ax.set_ylabel(r"RDF")
        fig.savefig("RDF_all.png")

        ref = MDAnalysis.Universe(filename, permissive=True)
        ref.trajectory[0]
        R = MDAnalysis.analysis.rms.RMSD(
            u,
            ref,
            select=
            "all",  # superimpose on whole backbone of all atoms # align based on all atoms
            groupselections=[rdf_fir, rdf_sec],
            filename="rmsd_all.dat",
            center=True)  #,   # CORE
        timestep = 0.0005  #0.5fs from fs to ps as Reader has no dt information, set to 1.0 ps
        R.run()
        rmsd = R.rmsd.T  # transpose makes it easier for plotting
        time = rmsd[1] * timestep

        da = {'time': time, 'all': rmsd[2], rdf_fir: rmsd[3], rdf_sec: rmsd[4]}
        df = pd.DataFrame(da)  #构造原始数据文件
        df.to_excel("RMSD.xlsx")  #生成Excel文件,并存到指定文件路径下

        fig = plt.figure(figsize=(5, 4))
        ax = fig.add_subplot(111)
        ax.plot(time, rmsd[2], 'k-', label="all")
        ax.plot(time, rmsd[3], 'r--', label=rdf_fir)
        ax.plot(time, rmsd[4], 'b--', label=rdf_sec)
        ax.legend(loc="best")
        ax.set_xlabel("time (ps)")
        ax.set_ylabel(r"RMSD ($\AA$)")
        fig.savefig("rmsd_md_analysis.png")