def test_extend(self): traj = self.traj.copy() # Case of compatible trajectories compatible_traj = Trajectory.from_file( os.path.join(PymatgenTest.TEST_FILES_DIR, "Traj_Combine_Test_XDATCAR_1")) traj.extend(compatible_traj) full_traj = Trajectory.from_file( os.path.join(PymatgenTest.TEST_FILES_DIR, "Traj_Combine_Test_XDATCAR_Full")) compatible_success = self._check_traj_equality(self.traj, full_traj) # Case of incompatible trajectories traj = self.traj.copy() incompatible_traj = Trajectory.from_file( os.path.join(PymatgenTest.TEST_FILES_DIR, "Traj_Combine_Test_XDATCAR_2")) incompatible_test_success = False try: traj.extend(incompatible_traj) except Exception: incompatible_test_success = True self.assertTrue(compatible_success and incompatible_test_success)
def test_variable_lattice(self): structure = self.structures[0] # Generate structures with different lattices structures = [] for i in range(10): new_lattice = np.dot(structure.lattice.matrix, np.diag(1 + np.random.random_sample(3) / 20)) temp_struct = structure.copy() temp_struct.lattice = Lattice(new_lattice) structures.append(temp_struct) traj = Trajectory.from_structures(structures, constant_lattice=False) # Check if lattices were properly stored self.assertTrue( all( np.allclose(struct.lattice.matrix, structures[i].lattice.matrix) for i, struct in enumerate(traj))) # Check if the file is written correctly when lattice is not constant. traj.write_Xdatcar(filename="traj_test_XDATCAR") # Load trajectory from written xdatcar and compare to original written_traj = Trajectory.from_file("traj_test_XDATCAR", constant_lattice=False) self._check_traj_equality(traj, written_traj) os.remove("traj_test_XDATCAR")
def test_xdatcar_write(self): self.traj.write_Xdatcar(filename="traj_test_XDATCAR") # Load trajectory from written xdatcar and compare to original written_traj = Trajectory.from_file(os.path.join("./", "traj_test_XDATCAR")) self._check_traj_equality(self.traj, written_traj)
def test_extend(self): traj = self.traj.copy() # Case of compatible trajectories compatible_traj = Trajectory.from_file(os.path.join(test_dir, "Traj_Combine_Test_XDATCAR_1")) traj.extend(compatible_traj) full_traj = Trajectory.from_file(os.path.join(test_dir, "Traj_Combine_Test_XDATCAR_Full")) compatible_success = self._check_traj_equality(self.traj, full_traj) # Case of incompatible trajectories traj = self.traj.copy() incompatible_traj = Trajectory.from_file(os.path.join(test_dir, "Traj_Combine_Test_XDATCAR_2")) incompatible_test_success=False try: traj.extend(incompatible_traj) except: incompatible_test_success=True self.assertTrue(compatible_success and incompatible_test_success)
''' 分析AIMD结果,计算MSD 和 conductivity ''' import os from pymatgen.core.trajectory import Trajectory from pymatgen.io.vasp.outputs import Xdatcar from pymatgen import Structure from pymatgen.analysis.diffusion_analyzer import DiffusionAnalyzer import numpy as np import pickle # 这一步是读取 XDATCAR,得到一系列结构信息 traj = Trajectory.from_file('XDATCAR') # 这一步是实例化 DiffusionAnalyzer 的类 # 并用 from_structures 方法初始化这个类; 900 是温度,2 是POTIM 的值,1是间隔步数 # 间隔步数(step_skip)不太容易理解,但是根据官方教程: # dt = timesteps * self.time_step * self.step_skip diff = DiffusionAnalyzer.from_structures(traj,'Li',900,2,1) # 可以用内置的 plot_msd 方法画出 MSD 图像 # 有些终端不能显示图像,这时候可以调用 export_msdt() 方法,得到数据后再自己作图 diff.plot_msd() # 接下来直接得到 离子迁移率, 单位是 mS/cm C = diff.conductivity with open('result.dat','w') as f: f.write('# AIMD result for Li-ion\n') f.write('temp\tconductivity\n')
def setUp(self): xdatcar = Xdatcar(os.path.join(test_dir, "Traj_XDATCAR")) self.traj = Trajectory.from_file(os.path.join(test_dir, "Traj_XDATCAR")) self.structures = xdatcar.structures
def setUp(self): xdatcar = Xdatcar(os.path.join(PymatgenTest.TEST_FILES_DIR, "Traj_XDATCAR")) self.traj = Trajectory.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "Traj_XDATCAR")) self.structures = xdatcar.structures
def setUp(self): xdatcar = Xdatcar(os.path.join(test_dir, "Traj_XDATCAR")) self.traj = Trajectory.from_file(os.path.join(test_dir, "Traj_XDATCAR")) self.structures = xdatcar.structures
rc('text', usetex=True) import matplotlib.pylab as pylab params = { 'legend.fontsize': '15', 'figure.figsize': (7, 6), 'axes.labelsize': 20, 'axes.titlesize': 20, 'xtick.labelsize': 16, 'ytick.labelsize': 16 } pylab.rcParams.update(params) trajectory = Trajectory.from_file("./vasprun_md.xml") trajectory.write_Xdatcar(filename='XDATCAR_temp') images = read_vasp_xdatcar('XDATCAR_temp', index=None) print("total number of frames: " + str(len(images))) os.remove('./XDATCAR_temp') reference_frame = read_vasp('./SPOSCAR') desc = SOAP(species=[55, 51, 53], rcut=6.0, nmax=9, lmax=9, sigma=0.3, periodic=True, crossover=True, sparse=False) ref_features = desc.create(reference_frame)