Ejemplo n.º 1
0
 def test_msd_bootstrap_d(self):
     """
     Test msd_bootstrap very few particles.
     """
     ordinate1 = np.random.randn(10, 10, 3)
     ordinate2 = np.random.randn(1, 1, 3)
     ordinate3 = np.random.randn(1, 1, 3)
     ordinate4 = np.random.randn(1, 1, 3)
     ordinate5 = np.random.randn(1, 1, 3)
     to_resample = [
         ordinate1,
         ordinate2,
         ordinate3,
         ordinate4,
         ordinate5,
     ]
     boot = diffusion.MSDBootstrap(np.linspace(100, 600, 5, dtype=int),
                                   to_resample,
                                   progress=False,
                                   n_resamples=1,
                                   max_resamples=10,
                                   sub_sample_dt=2)
     assert_equal(boot.dt.size, 1)
     assert_equal(len(boot.distributions), 1)
     assert_equal(boot.msd_observed.size, 1)
     assert_equal(boot.msd_sampled.size, 1)
Ejemplo n.º 2
0
 def test_msd_bootstrap_c(self):
     """
     Test msd_bootstrap for to go over the limit point.
     """
     ordinate1 = np.random.randn(5, 500, 3)
     ordinate2 = np.random.randn(5, 450, 3)
     ordinate3 = np.random.randn(5, 400, 3)
     ordinate4 = np.random.randn(5, 100, 3)
     ordinate5 = np.random.randn(5, 10, 3)
     to_resample = [
         ordinate1,
         ordinate2,
         ordinate3,
         ordinate4,
         ordinate5,
     ]
     boot = diffusion.MSDBootstrap(np.linspace(100, 600, 5, dtype=int),
                                   to_resample,
                                   progress=False,
                                   n_resamples=1,
                                   max_resamples=10,
                                   sub_sample_dt=2)
     assert_equal(boot.dt.size, 3)
     assert_equal(len(boot.distributions), 3)
     assert_equal(boot.msd_observed.size, 3)
     assert_equal(boot.msd_sampled.size, 3)
Ejemplo n.º 3
0
 def test_msd_bootstrap_b(self):
     """
     Test msd_bootstrap for initial uniform with progress.
     """
     ordinate = np.random.uniform(size=(100, 50, 3))
     to_resample = [np.array(ordinate) for i in range(1, 6)]
     boot = diffusion.MSDBootstrap(np.linspace(100, 600, 5, dtype=int),
                                   to_resample,
                                   progress=True,
                                   n_resamples=1,
                                   max_resamples=1000)
     assert_equal(boot.dt.size, 5)
     assert_equal(len(boot.distributions), 5)
     assert_equal(boot.msd_observed.size, 5)
     assert_equal(boot.msd_sampled.size, 5)
Ejemplo n.º 4
0
    def __init__(self,
                 trajectory,
                 parser_params,
                 bootstrap_params=None,
                 dtype='Xdatcar'):  # pragma: no cover
        if bootstrap_params is None:
            bootstrap_params = {}
        if dtype is 'Xdatcar':
            try:
                from pymatgen.io.vasp import Xdatcar
            except ModuleNotFoundError:
                raise ModuleNotFoundError(
                    "To use the Xdatcar file parsing, pymatgen must be installed."
                )
            if isinstance(trajectory, list):
                trajectory_list = (Xdatcar(f) for f in trajectory)
                structures = _flatten_list(
                    [x.structures for x in trajectory_list])
            else:
                xd = Xdatcar(trajectory)
                structures = xd.structures
            u = PymatgenParser(structures, **parser_params)
            self.first_structure = structures[0]
            dt = u.delta_t
            disp_3d = u.disp_3d
        elif dtype is 'IdenticalXdatcar':
            try:
                from pymatgen.io.vasp import Xdatcar
            except ModuleNotFoundError:
                raise ModuleNotFoundError(
                    "To use the Xdatcar file parsing, pymatgen must be installed."
                )
            u = [
                PymatgenParser(Xdatcar(f).structures, **parser_params)
                for f in trajectory
            ]
            joint_disp_3d = []
            for i in range(len(u[0].disp_3d)):
                disp = np.zeros(
                    (u[0].disp_3d[i].shape[0] * len(u),
                     u[0].disp_3d[i].shape[1], u[0].disp_3d[i].shape[2]))
                disp[:u[0].disp_3d[i].shape[0]] = u[0].disp_3d[i]
                for j in range(1, len(u)):
                    disp[u[0].disp_3d[i].shape[0] *
                         j:u[0].disp_3d[i].shape[0] *
                         (j + 1)] = u[j].disp_3d[i]
                joint_disp_3d.append(disp)
            dt = u[0].delta_t
            disp_3d = joint_disp_3d
        elif dtype is 'structures':
            u = PymatgenParser(trajectory, **parser_params)
            self.first_structure = trajectory[0]
            dt = u.delta_t
            disp_3d = u.disp_3d
        elif dtype == 'universe':
            u = MDAnalysisParser(trajectory, **parser_params)
            dt = u.delta_t
            disp_3d = u.disp_3d
        else:
            try:
                import MDAnalysis as mda
            except ModuleNotFoundError:
                raise ModuleNotFoundError(
                    "To use the MDAnalysis from file parsing, MDAnalysis must be installed."
                )
            universe = mda.Universe(*trajectory, format=dtype)
            u = MDAnalysisParser(universe, **parser_params)
            dt = u.delta_t
            disp_3d = u.disp_3d

        self._diff = diffusion.MSDBootstrap(dt, disp_3d, **bootstrap_params)

        self.dt = self._diff.dt
        self.msd_observed = self._diff.msd_observed
        self.distributions = self._diff.distributions