Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: MaterSim/PyXtal_FF
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.2.1
Choose a base ref
...
head repository: MaterSim/PyXtal_FF
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 11 commits
  • 10 files changed
  • 3 contributors

Commits on May 23, 2022

  1. Copy the full SHA
    d4710fd View commit details

Commits on Dec 19, 2022

  1. fix some tiny issue on PR model with stress

    qzhu committed Dec 19, 2022
    Copy the full SHA
    95ae214 View commit details

Commits on Dec 21, 2022

  1. update to v0.2.2

    qzhu committed Dec 21, 2022
    Copy the full SHA
    b9820b2 View commit details

Commits on Jun 5, 2023

  1. add weight_on option to SO3

    qzhu2017 committed Jun 5, 2023
    Copy the full SHA
    afaf729 View commit details

Commits on Jun 9, 2023

  1. move to v0.2.3

    qzhu2017 committed Jun 9, 2023
    Copy the full SHA
    171d35a View commit details

Commits on Jul 8, 2023

  1. Copy the full SHA
    eeacab9 View commit details
  2. fix primitive option

    qzhu2017 committed Jul 8, 2023
    Copy the full SHA
    3fb898f View commit details

Commits on Aug 17, 2023

  1. update phonpy dep

    qzhu2017 committed Aug 17, 2023
    Copy the full SHA
    3c180f7 View commit details
  2. update phonpy dep

    qzhu2017 committed Aug 17, 2023
    Copy the full SHA
    22d182b View commit details

Commits on Jan 6, 2024

  1. Update neuralnetwork class

    - move calculation of dxdr from calculate_loss into normalize function
    - modified the calculation of dxdr in calculate_loss and evaluate functions
    VScoldness committed Jan 6, 2024
    Copy the full SHA
    534edc5 View commit details

Commits on Jan 7, 2024

  1. Merge pull request #63 from VScoldness/master

    Update neuralnetwork class
    qzhu2017 authored Jan 7, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    41d01d8 View commit details
Showing with 73 additions and 51 deletions.
  1. +21 −21 .github/workflows/tests.yml
  2. +3 −3 docs/conf.py
  3. +1 −1 docs/index.rst
  4. +1 −0 pyxtal_ff/calculator/__init__.py
  5. +19 −7 pyxtal_ff/descriptors/SO3.py
  6. +16 −12 pyxtal_ff/models/neuralnetwork.py
  7. +7 −2 pyxtal_ff/models/polynomialregression.py
  8. +1 −1 pyxtal_ff/version.py
  9. +2 −2 requirements.txt
  10. +2 −2 setup.py
42 changes: 21 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -28,25 +28,25 @@ jobs:
run: |
python -m pytest pyxtal_ff/test_all.py
notebooks:
strategy:
matrix:
python-version: [ 3.7, 3.8 ]
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
#notebooks:
# strategy:
# matrix:
# python-version: [ 3.7, 3.8 ]
# os: [ ubuntu-latest, windows-latest ]
# runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install -U pip
pip install pytest nbmake
pip install -r requirements.txt
pip install .
- name: Test notebooks with pytest
run: |
pytest --nbmake ./examples --nbmake-timeout=3600
# steps:
# - uses: actions/checkout@v2
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
# - name: Install dependencies
# run: |
# python -m pip install -U pip
# pip install pytest nbmake
# pip install -r requirements.txt
# pip install .
# - name: Test notebooks with pytest
# run: |
# pytest --nbmake ./examples --nbmake-timeout=3600
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -19,13 +19,13 @@
# -- Project information -----------------------------------------------------

project = 'PyXtal_FF'
copyright = '2019-2021, Qiang Zhu, Howard Yanxon, David Zagaceta'
copyright = '2019-, Qiang Zhu, Howard Yanxon, David Zagaceta'
author = 'Qiang Zhu, Howard Yanxon, David Zagaceta'

# The short X.Y version
version = '0.2.1'
version = '0.2.3'
# The full version, including alpha/beta/rc tags
release = 'May 2022'
release = 'June 2023'


# -- General configuration ---------------------------------------------------
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ PyXtal_FF
======================================
The aim of PyXtalFF project is to provide an automated computational infrastructure to train the interatomic potentials for inorganic periodic systems from high-end quantum mechanical calculations.

The current version is ``0.2.1`` at `GitHub <https://github.com/qzhu2017/pyxtal_ff>`_.
The current version is ``0.2.3`` at `GitHub <https://github.com/qzhu2017/pyxtal_ff>`_.

Expect updates upon request by `Qiang Zhu\'s group <https://qzhu2017.github.io>`_ at University of Nevada Las Vegas.

1 change: 1 addition & 0 deletions pyxtal_ff/calculator/__init__.py
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ def calculate(self, atoms=None,

# pyxtal_ff and lammps uses: xx, yy, zz, xy, xz, yz
# ase uses: xx, yy, zz, yz, xz, xy
# vasp uses: xx, yy, zz, xy, yz, zx
# from eV/A^3 to GPa
self.results['stress_zbl'] = base_stress/units.GPa
self.results['energy_zbl'] = base_energy
26 changes: 19 additions & 7 deletions pyxtal_ff/descriptors/SO3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import division
import numpy as np
from ase.neighborlist import NeighborList
from ase.neighborlist import NeighborList, PrimitiveNeighborList
from optparse import OptionParser
from scipy.special import sph_harm, spherical_in
from ase import Atoms
@@ -17,9 +17,11 @@ class SO3:
rcut: float, cutoff radius for neighbor calculation
alpha: float, gaussian width parameter
derivative: bool, whether to calculate the gradient of not
weight_on: bool, if True, the neighbors with different type will be counted as negative
primitive: bool, use the asePrimitiveNeighborList
'''

def __init__(self, nmax=3, lmax=3, rcut=3.5, alpha=2.0, derivative=True, stress=False, cutoff_function='cosine'):
def __init__(self, nmax=3, lmax=3, rcut=3.5, alpha=2.0, derivative=True, stress=False, cutoff_function='cosine', weight_on=False, primitive=False):
# populate attributes
self.nmax = nmax
self.lmax = lmax
@@ -29,7 +31,9 @@ def __init__(self, nmax=3, lmax=3, rcut=3.5, alpha=2.0, derivative=True, stress=
self.stress = stress
self._type = "SO3"
self.cutoff_function = cutoff_function
return
self.weight_on = weight_on
self.primitive = primitive
#return

def __str__(self):
s = "SO3 descriptor with Cutoff: {:6.3f}".format(self.rcut)
@@ -176,7 +180,7 @@ def clear_memory(self):
'''
attrs = list(vars(self).keys())
for attr in attrs:
if attr not in {'_nmax', '_lmax', '_rcut', '_alpha', '_derivative', '_stress', '_cutoff_function'}:
if attr not in {'_nmax', '_lmax', '_rcut', '_alpha', '_derivative', '_stress', '_cutoff_function', 'weight_on', 'primitive'}:
delattr(self, attr)
return

@@ -320,8 +324,12 @@ def build_neighbor_list(self, atom_ids=None):
atom_ids = range(len(atoms))

cutoffs = [self.rcut/2]*len(atoms)
nl = NeighborList(cutoffs, self_interaction=False, bothways=True, skin=0.0)
nl.update(atoms)
if self.primitive:
nl = PrimitiveNeighborList(cutoffs, self_interaction=False, bothways=True, skin=0.0)
nl.build(atoms.pbc, atoms.cell, atoms.get_scaled_positions())
else:
nl = NeighborList(cutoffs, self_interaction=False, bothways=True, skin=0.0)
nl.update(atoms)

center_atoms = []
neighbors = []
@@ -339,7 +347,11 @@ def build_neighbor_list(self, atom_ids=None):
pos = atoms.positions[j] + np.dot(offset,atoms.get_cell()) - center_atom
center_atoms.append(center_atom)
neighbors.append(pos)
atomic_weights.append(atoms[j].number)
if self.weight_on and atoms[j].number != atoms[i].number:
factor = -1
else:
factor = 1
atomic_weights.append(factor*atoms[j].number)
neighbor_indices.append([i,j])

neighbor_indices = np.array(neighbor_indices, dtype=np.int64)
28 changes: 16 additions & 12 deletions pyxtal_ff/models/neuralnetwork.py
Original file line number Diff line number Diff line change
@@ -308,13 +308,7 @@ def evaluate(self, data, figname):
_Energy += _e
if self.force_coefficient:
dedx = torch.autograd.grad(_e, _x)[0]
_dxdr = value['dxdr'][element]

tmp = np.zeros([len(value['x'][element]), n_atoms, value['x'][element].shape[1], 3])
for _m in range(n_atoms):
rows = np.where(value['seq'][element][:,1]==_m)[0]
tmp[value['seq'][element][rows, 0], _m, :, :] += _dxdr[rows, :, :]
_Force -= torch.einsum("ik, ijkl->jl", dedx, torch.from_numpy(tmp))
_Force -= torch.einsum("ik, ijkl->jl", dedx, value['dxdr'][element])

if self.stress_coefficient and (data2['group'] in self.stress_group):
if self.force_coefficient is None:
@@ -495,11 +489,7 @@ def calculate_loss(self, models, batch):

if self.force_coefficient:
dedx[element] = torch.autograd.grad(_energy, _x, create_graph=True)[0]
tmp = np.zeros([len(x[element]), n_atoms, x[element].shape[1], 3])
for _m in range(n_atoms):
rows = np.where(seq[element][:,1]==_m)[0]
tmp[seq[element][rows, 0], _m, :, :] += dxdr[element][rows, :, :]
_force -= torch.einsum("ik, ijkl->jl", dedx[element], torch.from_numpy(tmp))
_force -= torch.einsum("ik, ijkl->jl", dedx[element], dxdr[element])

if self.stress_coefficient and (group in self.stress_group):
if self.force_coefficient is None:
@@ -1019,6 +1009,20 @@ def normalize(self, data, drange, unit, norm=[0., 1.]):
#d['seq'][element][:, 0] -= torch.min(d['seq'][element][:, 0]) #adjust the initial position
d['seq'][element][:, 0] -= np.min(d['seq'][element][:, 0]) #adjust the initial position

x, dxdr, seq = d['x'], d['dxdr'], d['seq']
n_atoms = sum(len(value) for value in x.values())
new_dxdr = {}
for element in x.keys():
if x[element].nelement() > 0:
tmp = np.zeros([len(x[element]), n_atoms, x[element].shape[1], 3])
for _m in range(n_atoms):
rows = np.where(seq[element][:,1]==_m)[0]
tmp[seq[element][rows, 0], _m, :, :] += dxdr[element][rows, :, :]
new_dxdr[element] = torch.from_numpy(tmp)
else:
new_dxdr[element] = torch.empty((30,3), dtype=torch.float)
d['dxdr'] = new_dxdr

db2[str(i)] = d

db1.close()
9 changes: 7 additions & 2 deletions pyxtal_ff/models/polynomialregression.py
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ def evaluate(self, data, figname):
_force.append(Force[m])

if self.stress_coefficient and (db[str(i)]['group'] in self.stress_group):
true_stress = np.array(db[str(i)]['stress'])#.flat[[0,3,5,3,1,4,5,4,2]]
true_stress = np.ravel(db[str(i)]['stress'])#.flat[[0,3,5,3,1,4,5,4,2]]
Stress = np.ravel(Stress)
for m in range(len(true_stress)):
stress.append(true_stress[m])
@@ -707,6 +707,11 @@ def parse_features(self, data):

for i in range(self.no_of_structures):
data = db[str(i)]
#for key in data.keys():
# if key in ['x', 'dxdr', 'rdxdr', 'seq', 'force']:
# print(key, data[key].shape)
# else:
# print(key, data[key])
#energy = np.array([data['energy']/len(data['elements'])])
energy = np.array([data['energy']])
w_energy = np.array([1.])
@@ -716,7 +721,7 @@ def parse_features(self, data):
w_force = np.array([self.force_coefficient]*len(force))

if self.stress_coefficient and (data['group'] in self.stress_group): # energy + forces + stress
stress = np.array(data['stress'])#.flat[[0,3,5,3,1,4,5,4,2]]
stress = np.array(data['stress']).ravel()#.flat[[0,3,5,3,1,4,5,4,2]]
w_stress = np.array([self.stress_coefficient]*len(stress))
self.stress_components += 6

2 changes: 1 addition & 1 deletion pyxtal_ff/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.1'
__version__ = '0.2.3'
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
numpy>=1.13.3
scipy>=1.6.1
matplotlib>=2.0.0
ase>=3.20.1
ase>=3.22.1
torch>=1.1.0
phonopy==2.3.2
phonopy>=2.19.0
spglib>=1.12.1
monty>=3.0.2
seekpath>=1.9.5
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -38,9 +38,9 @@
'numpy>=1.13.3',
'scipy>=1.6.1',
'matplotlib>=2.0.0',
'ase>=3.20.1',
'ase>=3.22.1',
'torch>=1.10.2',
'phonopy==2.3.2', #tmp fix
'phonopy==2.19.0',
'spglib>=1.12.1',
'monty>=3.0.2',
'seekpath>=1.9.5',