Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yomichi committed Nov 6, 2024
2 parents 7fa4b13 + abbb642 commit 0a11803
Show file tree
Hide file tree
Showing 96 changed files with 4,142 additions and 682 deletions.
27 changes: 18 additions & 9 deletions .github/workflows/Test_abICS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@

name: Test for abICS

on: [push]
on:
push:
schedule:
- cron: '0 0 1,15 * *' # JST 9:00 on 1st and 15th every month

jobs:
build:

runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
testname: [Unit, Sampling, ActiveLearn]
python-version: ['3.9', '3.12']
testname: [Unit, Sampling, ActiveLearnAenet, ActiveLearnNequip, ActiveLearnMLIP-3]
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -42,8 +45,14 @@ jobs:
cd ../potts_pamc
sh ./run.sh
;;
ActiveLearn ) cd tests/integration/active_learn
sh ./install_aenet.sh
sh ./run.sh ;;
ActiveLearnAenet ) cd tests/integration/active_learn_aenet
sh ./install_aenet.sh
sh ./run.sh ;;
ActiveLearnNequip ) cd tests/integration/active_learn_nequip
sh ./install_nequip.sh
sh ./run.sh ;;
ActiveLearnMLIP-3 ) cd tests/integration/active_learn_mlip3
sh ./install_mlip3.sh
sh ./run.sh ;;
* ) echo "Unknown testname";;
esac
6 changes: 3 additions & 3 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ on: [push]

jobs:
check-build-doc:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.9

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ on:
jobs:
deploy:
timeout-minutes: 10.0
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Inject slug/short variables
uses: rlespinasse/[email protected]

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: main

- name: Checkout gh-pages
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.9

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ on:

jobs:
deploy:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.9

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ and OpenMX input files for obtaining the reference training data for the machine

## Requirement

- python3 (>=3.7)
- python3 (>=3.9)
- numpy
- scipy
- toml (for parsing input files)
- mpi4py (for parallel tempering)
- This requires one of the MPI implementation
- pymatgen (>=2019.12.3) (for using Structure as a configuration)
- pymatgen (>=2022.1.20) (for using Structure as a configuration)
- This requires Cython
- qe-tools (for parsing QE I/O)

Expand All @@ -25,7 +25,7 @@ Pymatgen requires Cython but Cython will not be installed automatically,
please make sure that this is installed,

``` bash
$ pip3 install Cython
$ python3 -m pip install Cython
```

mpi4py requires one of the MPI implementations such as OpenMPI,
Expand All @@ -39,7 +39,7 @@ $ brew install open-mpi
After installing Cython and MPI,

``` bash
$ pip3 install abics
$ python3 -m pip install abics
```

will install abICS and dependencies.
Expand All @@ -48,10 +48,10 @@ If you want to change the directory where abICS is installed,
add `--user` option or `--prefix=DIRECTORY` option to the above command as

``` bash
$ pip3 install --user abics
$ python3 -m pip install --user abics
```

For details of `pip` , see the manual of `pip` by `pip3 help install`
For details of `pip` , see the manual of `pip` by `python3 -m pip help install`

If you want to install abICS from source, see [wiki page](https://github.com/issp-center-dev/abICS/wiki/Install)

Expand Down Expand Up @@ -93,6 +93,6 @@ Shusuke Kasamatsu, Yuichi Motoyama, Tatsumi Aoyama, Kazuyoshi Yoshimi

[English online manual](https://issp-center-dev.github.io/abICS/docs/master/en/html/index.html)

[Japnese online manual](https://issp-center-dev.github.io/abICS/docs/master/ja/html/index.html)
[Japanese online manual](https://issp-center-dev.github.io/abICS/docs/master/ja/html/index.html)

[API reference](https://issp-center-dev.github.io/abICS/docs/api/master/html/index.html)
2 changes: 1 addition & 1 deletion abics/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.0"
__version__ = "2.2.0"
22 changes: 14 additions & 8 deletions abics/applications/latgas_abinitio_interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.

# from .default_observer import *
from .map2perflat import *
from .aenet_trainer import *

from .vasp import VASPSolver
from .qe import QESolver
from .aenet import AenetSolver
from .aenet_pylammps import AenetPyLammpsSolver
from .openmx import OpenMXSolver
from .user_function_solver import UserFunctionSolver
from .base_solver import register_solver
from .base_trainer import register_trainer

register_solver("vasp", "VASPSolver", "abics.applications.latgas_abinitio_interface.vasp")
register_solver("qe", "QESolver", "abics.applications.latgas_abinitio_interface.qe")
register_solver("openmx", "OpenMXSolver", "abics.applications.latgas_abinitio_interface.openmx")
register_solver("aenet", "AenetSolver", "abics.applications.latgas_abinitio_interface.aenet")
register_solver("nequip", "NequipSolver", "abics.applications.latgas_abinitio_interface.nequip")
register_solver("mlip_3", "MLIP3Solver", "abics.applications.latgas_abinitio_interface.mlip_3")
register_solver("User", "UserFunctionSolver", "abics.applications.latgas_abinitio_interface.user_function_solver")

register_trainer("aenet", "AenetTrainer", "abics.applications.latgas_abinitio_interface.aenet_trainer")
register_trainer("nequip", "NequipTrainer", "abics.applications.latgas_abinitio_interface.nequip_trainer")
register_trainer("mlip_3", "MLIP3Trainer", "abics.applications.latgas_abinitio_interface.mlip_3_trainer")
112 changes: 4 additions & 108 deletions abics/applications/latgas_abinitio_interface/aenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.

"""
Adapted from pymatgen.io.xcrysden distributed under the MIT License
# Copyright (c) Pymatgen Development Team.
# Distributed under the terms of the MIT License.
"""

from __future__ import annotations

import os
Expand All @@ -28,105 +22,9 @@
import numpy as np
from pymatgen.core import Structure

from .base_solver import SolverBase, register_solver
from .base_solver import SolverBase
from .params import ALParams, DFTParams


def to_XSF(structure: Structure, write_force_zero=False):
"""
Returns a string with the structure in XSF format
See http://www.xcrysden.org/doc/XSF.html
"""
lines = []
app = lines.append

app("CRYSTAL")
app("# Primitive lattice vectors in Angstrom")
app("PRIMVEC")
cell = structure.lattice.matrix
for i in range(3):
app(" %.14f %.14f %.14f" % tuple(cell[i]))

cart_coords = structure.cart_coords
app("# Cartesian coordinates in Angstrom.")
app("PRIMCOORD")
app(" %d 1" % len(cart_coords))
species = structure.species
site_properties = structure.site_properties
if "forces" not in site_properties.keys():
write_force_zero = True
else:
forces = site_properties["forces"]

if write_force_zero:
for a in range(len(cart_coords)):
app(
str(species[a])
+ " %20.14f %20.14f %20.14f" % tuple(cart_coords[a])
+ " 0.0 0.0 0.0"
)
else:
for a in range(len(cart_coords)):
app(
str(species[a])
+ " %20.14f %20.14f %20.14f" % tuple(cart_coords[a])
+ " %20.14f %20.14f %20.14f" % tuple(forces[a])
)

return "\n".join(lines)


def from_XSF(input_string: str):
"""
Initialize a `Structure` object from a string with data in XSF format.
Args:
input_string: String with the structure in XSF format.
See http://www.xcrysden.org/doc/XSF.html
cls_: Structure class to be created. default: pymatgen structure
"""
# CRYSTAL see (1)
# these are primitive lattice vectors (in Angstroms)
# PRIMVEC
# 0.0000000 2.7100000 2.7100000 see (2)
# 2.7100000 0.0000000 2.7100000
# 2.7100000 2.7100000 0.0000000

# these are conventional lattice vectors (in Angstroms)
# CONVVEC
# 5.4200000 0.0000000 0.0000000 see (3)
# 0.0000000 5.4200000 0.0000000
# 0.0000000 0.0000000 5.4200000

# these are atomic coordinates in a primitive unit cell (in Angstroms)
# PRIMCOORD
# 2 1 see (4)
# 16 0.0000000 0.0000000 0.0000000 see (5)
# 30 1.3550000 -1.3550000 -1.3550000

lattice, coords, species = [], [], []
lines = input_string.splitlines()

for i in range(len(lines)):
if "PRIMVEC" in lines[i]:
for j in range(i + 1, i + 4):
lattice.append([float(c) for c in lines[j].split()])

if "PRIMCOORD" in lines[i]:
num_sites = int(lines[i + 1].split()[0])

for j in range(i + 2, i + 2 + num_sites):
tokens = lines[j].split()
species.append(tokens[0])
coords.append([float(j) for j in tokens[1:4]])
break
else:
raise ValueError("Invalid XSF data")

s = Structure(lattice, species, coords, coords_are_cartesian=True)
return s

from .util import structure_to_XSF, structure_from_XSF

class AenetSolver(SolverBase):
"""
Expand Down Expand Up @@ -183,7 +81,7 @@ def update_info_by_structure(self, structure: Structure):
if self.ignore_species is not None:
structure = structure.copy()
structure.remove_species(self.ignore_species)
self.pos_info = to_XSF(structure)
self.pos_info = structure_to_XSF(structure)

def update_info_from_files(self, output_dir, rerun):
"""
Expand Down Expand Up @@ -262,7 +160,7 @@ def get_results(self, output_dir):
# Read results from files in output_dir and calculate values
Phys = namedtuple("PhysValues", ("energy", "structure"))
with open(os.path.join(output_dir, "structure.xsf")) as f:
structure = from_XSF(f.read())
structure = structure_from_XSF(f.read())
with open(os.path.join(output_dir, "stdout")) as f:
lines = f.read()
fi_io = io.StringIO(lines)
Expand Down Expand Up @@ -291,5 +189,3 @@ def create(cls, params: ALParams | DFTParams):
ignore_species = params.ignore_species
run_scheme = params.solver_run_scheme
return cls(path, ignore_species, run_scheme)

register_solver("aenet", AenetSolver)
16 changes: 8 additions & 8 deletions abics/applications/latgas_abinitio_interface/aenet_pylammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import numpy as np
from pymatgen.core import Structure

from .base_solver import SolverBase, register_solver
from .base_solver import SolverBase
from .params import ALParams, DFTParams


Expand Down Expand Up @@ -62,7 +62,9 @@ def __init__(self, ignore_species):
self.calc = lammps(
cmdargs=["-log", "none", "-screen", "none", "-nocite"], comm=MPI.COMM_SELF
)

self.rank = MPI.COMM_WORLD.Get_rank()

# debug cmdargs=["-log", "test{}.log".format(MPI.COMM_WORLD.Get_rank()), "-screen", "none", "-nocite"], comm=MPI.COMM_SELF
def name(self):
return "aenetPyLammps"

Expand All @@ -77,21 +79,22 @@ def calculate_energy(self, fi, output_dir):
latt = st.lattice.matrix
ax = np.linalg.norm(latt[0])
bx = np.dot(latt[1], unit_vec(latt[0]))
by = np.linalg.norm(np.outer(unit_vec(latt[0]), latt[1]))
by = np.linalg.norm(np.cross(unit_vec(latt[0]), latt[1]))
cx = np.dot(latt[2], unit_vec(latt[0]))
cy = (np.dot(latt[1], latt[2]) - bx * cx) / by
cz = np.sqrt(np.linalg.norm(latt[2]) ** 2.0 - cx ** 2.0 - cy ** 2.0)

# lmp = lammps(cmdargs=["-log", "none","-nocite"])

self.calc.command("atom_style atomic")
self.calc.command("units metal")
self.calc.command("boundary p p p")

self.calc.command(f"region box prism 0 {ax} 0 {by} 0 {cz} {bx} {cx} {cy}")
self.calc.command(f"create_box {nspec} box")
types = list(map(lambda x: spec_dict[x.name], st.species))
self.calc.create_atoms(natoms, None, types, st.cart_coords.ravel())
new_coords = np.dot(st.frac_coords, np.array([[ax,0,0], [bx,by,0], [cx,cy,cz]]))
self.calc.create_atoms(natoms, None, types, new_coords.ravel())

for i in range(1, nspec + 1):
self.calc.command(f"mass {i} 1")
self.calc.commands_list(self.input.pair_pot)
Expand Down Expand Up @@ -224,6 +227,3 @@ def solver_run_schemes(self):
def create(cls, params: ALParams | DFTParams):
ignore_species = params.ignore_species
return cls(ignore_species)


register_solver("aenetpylammps", AenetPyLammpsSolver)
Loading

0 comments on commit 0a11803

Please sign in to comment.