Note
Go to the end to download the full example code.
Data File Reader¶
The DataFileParser handles LAMMPS data files containing complete system definitions.
The UniverseSequence provides a convenient way to have these data files read
into the Universe objects.
import os
from pathlib import Path
from pylimer_tools_cpp import UniverseSequence
def _find_fixtures_dir() -> Path:
for cur in (
[Path(__file__).resolve().parent] if "__file__" in globals() else []
) + [Path.cwd()]:
for p in [cur] + list(cur.parents):
candidate = p / "tests" / "pylimer_tools" / "fixtures"
if candidate.is_dir():
return candidate
return Path("tests/pylimer_tools/fixtures").resolve()
_fixtures_dir = _find_fixtures_dir()
base_structure_path = str(_fixtures_dir / "structure")
# Load a single data file
data_file = os.path.join(
base_structure_path,
"melt_83_a_100.structure.out",
)
one_universe_seq = UniverseSequence()
one_universe_seq.initialize_from_data_sequence([data_file])
universe = one_universe_seq.at_index(0)
# Load multiple data files as a sequence
sequence = UniverseSequence()
sequence.initialize_from_data_sequence(
[
os.path.join(
base_structure_path,
"3d-diamond-lattice_10x10x10_a_3_d_0.85_imperfect.structure.out",
),
os.path.join(
base_structure_path,
"3d-diamond-lattice_10x10x10_a_3_d_0.85_v_0.V-fixed.structure.out",
),
]
)
for universe in sequence:
print(f"Loaded universe with {universe.get_nr_of_atoms()} atoms")
Loaded universe with 56000 atoms
Loaded universe with 56000 atoms
Please note that the hybrid and tdpd atom styles are not fully supported.
If your data files don’t hint the atom style in the line that starts with “Atom”,
you should specify it manually, see read()
and set_data_file_atom_style().
Total running time of the script: (0 minutes 0.130 seconds)