Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build): Add Git archives version files #636

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git_archival.txt export-subst
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
python-version: ["3.7", "3.8", "3.12"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
# set up conda
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# install rdkit and openbabel
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_import.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
architecture: 'x64'
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
# there are many log files in tests
# TODO: seperate py files and log files
Expand Down
18 changes: 18 additions & 0 deletions dpdata/plugins/pymatgen.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
import numpy as np

import dpdata.pymatgen.molecule
import dpdata.pymatgen.structure
from dpdata.format import Format


@Format.register("pymatgen/structure")
class PyMatgenStructureFormat(Format):
def from_system(self, structure, **kwargs) -> dict:
"""Convert pymatgen.core.Structure to System.

Parameters
----------
structure : pymatgen.core.Structure
a Pymatgen Structure, containing a structure
**kwargs : dict
other parameters

Returns
-------
dict
data dict
"""
return dpdata.pymatgen.structure.from_system_data(structure)

def to_system(self, data, **kwargs):
"""Convert System to Pymatgen Structure obj."""
structures = []
Expand Down
24 changes: 24 additions & 0 deletions dpdata/pymatgen/structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import numpy as np

try:
from pymatgen.core import Structure # noqa: F401
except ImportError:
pass


def from_system_data(structure) -> dict:
symbols = [site.species_string for site in structure]
atom_names = list(structure.symbol_set)
atom_numbs = [symbols.count(symbol) for symbol in atom_names]
atom_types = np.array([atom_names.index(symbol) for symbol in symbols]).astype(int)
coords = structure.cart_coords
cells = structure.lattice.matrix

info_dict = {
"atom_names": atom_names,
"atom_numbs": atom_numbs,
"atom_types": atom_types,
"coords": np.array([coords]),
"cells": np.array([cells]),
}
return info_dict
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=61", "setuptools_scm[toml]>=6.2"]
requires = ["setuptools>=61", "setuptools_scm[toml]>=7"]
build-backend = "setuptools.build_meta"

[project]
Expand Down
30 changes: 30 additions & 0 deletions tests/test_from_pymatgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import unittest

from comp_sys import CompSys
from context import dpdata

try:
from pymatgen.core import Structure # noqa: F401

exist_module = True
except Exception:
exist_module = False


@unittest.skipIf(not exist_module, "skip pymatgen")
class TestFormPytmatgen(unittest.TestCase, CompSys):
def setUp(self):
structure = Structure.from_file(os.path.join("poscars", "POSCAR.P42nmc"))
self.system_1 = dpdata.System(structure, fmt="pymatgen/structure")
self.system_2 = dpdata.System(
os.path.join("poscars", "POSCAR.P42nmc"), fmt="poscar"
)
self.places = 6
self.e_places = 6
self.f_places = 6
self.v_places = 6


if __name__ == "__main__":
unittest.main()
4 changes: 2 additions & 2 deletions tests/test_to_pymatgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from context import dpdata

try:
from pymatgen import Structure # noqa: F401
from pymatgen.core import Structure # noqa: F401

exist_module = True
except Exception:
Expand All @@ -19,7 +19,7 @@ def setUp(self):
system_1.from_lammps_lmp(
os.path.join("poscars", "conf.lmp"), type_map=["O", "H"]
)
system_1.to_pymatgen_structure()[0].to("poscar", "tmp.POSCAR")
system_1.to_pymatgen_structure()[0].to(filename="tmp.POSCAR", fmt="poscar")
self.system_1 = system_1
self.system_2 = dpdata.System("tmp.POSCAR")
self.places = 6
Expand Down