Skip to content

Commit

Permalink
Initial support for parsing LMP files
Browse files Browse the repository at this point in the history
  • Loading branch information
hexane360 committed Apr 5, 2024
1 parent a2360e2 commit 5dea968
Show file tree
Hide file tree
Showing 12 changed files with 920 additions and 78 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ This means you can write your own code to utilize advanced format features even
| [Basic XYZ][xyz] | .xyz | :white_check_mark: | :white_check_mark: | |
| [Ext. XYZ][xyz] | .exyz | :white_check_mark: | :white_check_mark: | Arbitrary properties not implemented |
| [Special XYZ][xyz] | .sxyz | :x: | :x: | To be implemented |
| [LAMMPS Data][lmp] | .lmp | :x: | :white_check_mark: | |
| [LAMMPS Data][lmp] | .lmp | :white_check_mark: | :white_check_mark: | |
| [Quantum Espresso][qe] | .qe | :x: | :white_check_mark: | pw.x format |
| [pyMultislicer][pyM] | .mslice | :white_check_mark: | :white_check_mark: | |
| [pyMultislicer][pyM] | .mslice | :white_check_mark: | :white_check_mark: | Currently XML format only |

[atomsk]: https://atomsk.univ-lille.fr/
[ase]: https://wiki.fysik.dtu.dk/ase/
Expand Down
2 changes: 1 addition & 1 deletion atomlib/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def with_cell(self: Cell, cell: Cell) -> Cell:
def __init__(self, *,
affine: t.Optional[AffineTransform3D] = None, ortho: t.Optional[LinearTransform3D] = None,
cell_size: VecLike, cell_angle: t.Optional[VecLike] = None,
n_cells: t.Optional[VecLike] = None, pbc: t.Optional[VecLike]):
n_cells: t.Optional[VecLike] = None, pbc: t.Optional[VecLike] = None):

object.__setattr__(self, '_affine', AffineTransform3D() if affine is None else affine)
object.__setattr__(self, '_ortho', LinearTransform3D() if ortho is None else ortho)
Expand Down
30 changes: 24 additions & 6 deletions atomlib/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .xsf import XSF
from .cfg import CFG
from .mslice import write_mslice, read_mslice
from .lmp import write_lmp
from .lmp import LMP
from .qe import write_qe

from ..atoms import Atoms, HasAtoms
Expand Down Expand Up @@ -73,9 +73,9 @@ def read_cif(f: t.Union[FileOrPath, CIF, CIFDataBlock], block: t.Union[int, str,
for sym in cif.get_symmetry():
sym_atoms.append(atoms.transform(sym))

s = '\n'.join(map(str, sym_atoms))
print(f"sym_atoms:\n{s}")
print(f"atoms: {atoms!s}")
#s = '\n'.join(map(str, sym_atoms))
#print(f"sym_atoms:\n{s}")
#print(f"atoms: {atoms!s}")

if len(sym_atoms) > 0:
atoms = Atoms.concat(sym_atoms)._wrap().deduplicate()
Expand Down Expand Up @@ -176,19 +176,37 @@ def read_cfg(f: t.Union[FileOrPath, CFG]) -> AtomCell:


def write_cfg(atoms: t.Union[HasAtoms, CFG], f: FileOrPath):
"""Write a structure to an AtomEye CFG file."""
if not isinstance(atoms, CFG):
atoms = CFG.from_atoms(atoms)
atoms.write(f)


def read_lmp(f: t.Union[FileOrPath, LMP], type_map: t.Optional[t.Dict[int, t.Union[str, int]]] = None) -> AtomCell:
"""Read a structure from a LAAMPS data file."""
if isinstance(f, LMP):
lmp = f
else:
lmp = LMP.from_file(f)

return lmp.get_atoms(type_map=type_map)


def write_lmp(atoms: t.Union[HasAtoms, LMP], f: FileOrPath):
"""Write a structure to a LAAMPS data file."""
if not isinstance(atoms, LMP):
atoms = LMP.from_atoms(atoms)
atoms.write(f)


ReadFunc = t.Callable[[FileOrPath], HasAtoms]
_READ_TABLE: t.Mapping[FileType, t.Optional[ReadFunc]] = {
'cif': read_cif,
'xyz': read_xyz,
'xsf': read_xsf,
'cfg': read_cfg,
'mslice': read_mslice,
'lmp': None,
'lmp': read_lmp,
'qe': None
}

Expand Down Expand Up @@ -294,7 +312,7 @@ def write(atoms: HasAtoms, path: FileOrPath, ty: t.Optional[FileType] = None):


__all__ = [
'CIF', 'XYZ', 'XSF', 'CFG',
'CIF', 'XYZ', 'XSF', 'CFG', 'LMP',
'read', 'read_cif', 'read_xyz', 'read_xsf', 'read_cfg',
'write', 'write_xyz', 'write_xsf', 'write_cfg', 'write_lmp', 'write_mslice', 'write_qe',
]
Loading

0 comments on commit 5dea968

Please sign in to comment.