|
4 | 4 | import os
|
5 | 5 | import re
|
6 | 6 | import shutil
|
7 |
| -import tempfile |
8 | 7 | import unittest
|
9 |
| -from pathlib import Path |
10 | 8 |
|
11 | 9 | import pandas as pd
|
12 | 10 | import pytest
|
@@ -671,45 +669,43 @@ def tearDownClass(cls):
|
671 | 669 |
|
672 | 670 | class LammpsTemplateGenTest(PymatgenTest):
|
673 | 671 | def test_write_inputs(self):
|
674 |
| - with tempfile.TemporaryDirectory() as tmp_dir: |
675 |
| - # simple script without data file |
676 |
| - lis = LammpsTemplateGen().get_input_set( |
677 |
| - script_template=f"{PymatgenTest.TEST_FILES_DIR}/lammps/kappa.txt", |
678 |
| - settings={"method": "heat"}, |
679 |
| - data=None, |
680 |
| - data_filename="data.peptide", |
681 |
| - ) |
682 |
| - tmp_dir = Path(tmp_dir) |
683 |
| - assert len(lis) == 1 |
684 |
| - lis.write_input(tmp_dir / "heat") |
685 |
| - |
686 |
| - with open(tmp_dir / "heat" / "in.lammps") as f: |
687 |
| - kappa_script = f.read() |
688 |
| - fix_hot = re.search(r"fix\s+hot\s+all\s+([^\s]+)\s+", kappa_script) |
689 |
| - # placeholders supposed to be filled |
690 |
| - assert fix_hot.group(1) == "heat" |
691 |
| - fix_cold = re.search(r"fix\s+cold\s+all\s+([^\s]+)\s+", kappa_script) |
692 |
| - assert fix_cold.group(1) == "heat" |
693 |
| - lattice = re.search(r"lattice\s+fcc\s+(.*)\n", kappa_script) |
694 |
| - # parentheses not supposed to be filled |
695 |
| - assert lattice.group(1) == "${rho}" |
696 |
| - pair_style = re.search(r"pair_style\slj/cut\s+(.*)\n", kappa_script) |
697 |
| - assert pair_style.group(1) == "${rc}" |
698 |
| - |
699 |
| - # script with data file |
700 |
| - obj = LammpsData.from_file( |
701 |
| - os.path.join(PymatgenTest.TEST_FILES_DIR, "lammps", "data.quartz"), atom_style="atomic" |
702 |
| - ) |
703 |
| - lis = LammpsTemplateGen().get_input_set( |
704 |
| - script_template=f"{PymatgenTest.TEST_FILES_DIR}/lammps/in.peptide", |
705 |
| - settings=None, |
706 |
| - data=obj, |
707 |
| - data_filename="data.peptide", |
708 |
| - ) |
709 |
| - assert len(lis) == 2 |
710 |
| - assert isinstance(lis["data.peptide"], LammpsData) |
711 |
| - lis.write_input(tmp_dir / "obj") |
712 |
| - |
713 |
| - obj_read = LammpsData.from_file(str(tmp_dir / "obj" / "data.peptide"), atom_style="atomic") |
714 |
| - pd.testing.assert_frame_equal(obj_read.masses, obj.masses) |
715 |
| - pd.testing.assert_frame_equal(obj_read.atoms, obj.atoms) |
| 672 | + # simple script without data file |
| 673 | + lis = LammpsTemplateGen().get_input_set( |
| 674 | + script_template=f"{PymatgenTest.TEST_FILES_DIR}/lammps/kappa.txt", |
| 675 | + settings={"method": "heat"}, |
| 676 | + data=None, |
| 677 | + data_filename="data.peptide", |
| 678 | + ) |
| 679 | + assert len(lis) == 1 |
| 680 | + lis.write_input(self.tmp_path / "heat") |
| 681 | + |
| 682 | + with open(self.tmp_path / "heat" / "in.lammps") as f: |
| 683 | + kappa_script = f.read() |
| 684 | + fix_hot = re.search(r"fix\s+hot\s+all\s+([^\s]+)\s+", kappa_script) |
| 685 | + # placeholders supposed to be filled |
| 686 | + assert fix_hot.group(1) == "heat" |
| 687 | + fix_cold = re.search(r"fix\s+cold\s+all\s+([^\s]+)\s+", kappa_script) |
| 688 | + assert fix_cold.group(1) == "heat" |
| 689 | + lattice = re.search(r"lattice\s+fcc\s+(.*)\n", kappa_script) |
| 690 | + # parentheses not supposed to be filled |
| 691 | + assert lattice.group(1) == "${rho}" |
| 692 | + pair_style = re.search(r"pair_style\slj/cut\s+(.*)\n", kappa_script) |
| 693 | + assert pair_style.group(1) == "${rc}" |
| 694 | + |
| 695 | + # script with data file |
| 696 | + obj = LammpsData.from_file( |
| 697 | + os.path.join(PymatgenTest.TEST_FILES_DIR, "lammps", "data.quartz"), atom_style="atomic" |
| 698 | + ) |
| 699 | + lis = LammpsTemplateGen().get_input_set( |
| 700 | + script_template=f"{PymatgenTest.TEST_FILES_DIR}/lammps/in.peptide", |
| 701 | + settings=None, |
| 702 | + data=obj, |
| 703 | + data_filename="data.peptide", |
| 704 | + ) |
| 705 | + assert len(lis) == 2 |
| 706 | + assert isinstance(lis["data.peptide"], LammpsData) |
| 707 | + lis.write_input(self.tmp_path / "obj") |
| 708 | + |
| 709 | + obj_read = LammpsData.from_file(str(self.tmp_path / "obj" / "data.peptide"), atom_style="atomic") |
| 710 | + pd.testing.assert_frame_equal(obj_read.masses, obj.masses) |
| 711 | + pd.testing.assert_frame_equal(obj_read.atoms, obj.atoms) |
0 commit comments