Skip to content

Commit

Permalink
Merge pull request #52 from phonopy/refactoring
Browse files Browse the repository at this point in the history
(refactoring) Clear separation of phonopy instances for phelel and for extra phonon
atztogo authored Jan 4, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents c7a8461 + b45f30f commit 86467bc
Showing 16 changed files with 709 additions and 212 deletions.
25 changes: 25 additions & 0 deletions example/PbTe/POSCAR-unitcell
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
generated by phonopy
1.00000000000000
6.4405958992591392 0.0000000000000000 0.0000000000000000
0.0000000000000000 6.4405958992591392 0.0000000000000000
0.0000000000000000 0.0000000000000000 6.4405958992591392
Pb Te
4 4
Direct
0.0000000000000000 0.0000000000000000 0.0000000000000000
0.0000000000000000 0.5000000000000000 0.5000000000000000
0.5000000000000000 0.0000000000000000 0.5000000000000000
0.5000000000000000 0.5000000000000000 0.0000000000000000
0.5000000000000000 0.5000000000000000 0.5000000000000000
0.5000000000000000 0.0000000000000000 0.0000000000000000
0.0000000000000000 0.5000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000 0.5000000000000000

0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
30 changes: 30 additions & 0 deletions example/PbTe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# PbTe example

Conventional unit cell of rocksalt-type PbTe crystal structure is stored in
`POSCAR-unitcell`. This structure is relaxed with 400 eV cutoff energy and
PBEsol XC functional. More detail of the relaxation calculation is found in
`velph-tmpl.toml`.

2x2x2 supercell of the unit cell and the supercells with displacements are
generated by

```
% phelel -d --dim 2 2 2 -c POSCAR-unitcell --pa auto --pm
```

By this command, following files are created. `phelel_disp.yaml` contains
crystal structure information and `SPOSCAR`, `POSCAR-001`, `POSCAR-002`,
`POSCAR-003`, `POSCAR-004` files are the perfect supercell and supercells with
four different displacements, respectively.

Let's assume that these supercell calculations are executed in `disp-000`,
`disp-001`, `disp-002`, `disp-003`, and `disp-004`. After the VASP calculations
(`LWAP=.TRUE.` or `ELPH_PREPARE=.TRUE.` in `INCAR` is necessary), phelel
computes derivatives of local potential and PAW strengths with respect to
displacements by

```
% phelel --cd disp-{000..004}
```

The result is stored in `phelel_params.hdf5`.
362 changes: 362 additions & 0 deletions example/PbTe/phelel_disp_reference.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,362 @@
phelel:
version: "0.7.0"
calculator: vasp
symmetry_tolerance: 1.00000e-05
configuration:
cell_filename: "POSCAR-unitcell"
create_displacements: ".true."
pm: ".true."
primitive_axes: "auto"
dim: "2 2 2"

physical_unit:
atomic_mass: "AMU"
length: "angstrom"

space_group:
type: "Fm-3m"
number: 225
Hall_symbol: "-F 4 2 3"

primitive_matrix:
- [ 0.000000000000000, 0.500000000000000, 0.500000000000000 ]
- [ 0.500000000000000, 0.000000000000000, 0.500000000000000 ]
- [ 0.500000000000000, 0.500000000000000, 0.000000000000000 ]

supercell_matrix:
- [ 2, 0, 0 ]
- [ 0, 2, 0 ]
- [ 0, 0, 2 ]

primitive_cell:
lattice:
- [ 0.000000000000000, 3.220297949629569, 3.220297949629569 ] # a
- [ 3.220297949629569, 0.000000000000000, 3.220297949629569 ] # b
- [ 3.220297949629569, 3.220297949629569, 0.000000000000000 ] # c
points:
- symbol: Pb # 1
coordinates: [ 0.000000000000000, 0.000000000000000, 0.000000000000000 ]
mass: 207.200000
- symbol: Te # 2
coordinates: [ 0.500000000000000, 0.500000000000000, 0.500000000000000 ]
mass: 127.600000
reciprocal_lattice: # without 2pi
- [ -0.155265136276448, 0.155265136276448, 0.155265136276448 ] # a*
- [ 0.155265136276448, -0.155265136276448, 0.155265136276448 ] # b*
- [ 0.155265136276448, 0.155265136276448, -0.155265136276448 ] # c*

unit_cell:
lattice:
- [ 6.440595899259139, 0.000000000000000, 0.000000000000000 ] # a
- [ 0.000000000000000, 6.440595899259139, 0.000000000000000 ] # b
- [ 0.000000000000000, 0.000000000000000, 6.440595899259139 ] # c
points:
- symbol: Pb # 1
coordinates: [ 0.000000000000000, 0.000000000000000, 0.000000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 2
coordinates: [ 0.000000000000000, 0.500000000000000, 0.500000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 3
coordinates: [ 0.500000000000000, 0.000000000000000, 0.500000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 4
coordinates: [ 0.500000000000000, 0.500000000000000, 0.000000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Te # 5
coordinates: [ 0.500000000000000, 0.500000000000000, 0.500000000000000 ]
mass: 127.600000
reduced_to: 5
- symbol: Te # 6
coordinates: [ 0.500000000000000, 0.000000000000000, 0.000000000000000 ]
mass: 127.600000
reduced_to: 5
- symbol: Te # 7
coordinates: [ 0.000000000000000, 0.500000000000000, 0.000000000000000 ]
mass: 127.600000
reduced_to: 5
- symbol: Te # 8
coordinates: [ 0.000000000000000, 0.000000000000000, 0.500000000000000 ]
mass: 127.600000
reduced_to: 5

supercell:
lattice:
- [ 12.881191798518278, 0.000000000000000, 0.000000000000000 ] # a
- [ 0.000000000000000, 12.881191798518278, 0.000000000000000 ] # b
- [ 0.000000000000000, 0.000000000000000, 12.881191798518278 ] # c
points:
- symbol: Pb # 1
coordinates: [ 0.000000000000000, 0.000000000000000, 0.000000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 2
coordinates: [ 0.500000000000000, 0.000000000000000, 0.000000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 3
coordinates: [ 0.000000000000000, 0.500000000000000, 0.000000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 4
coordinates: [ 0.500000000000000, 0.500000000000000, 0.000000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 5
coordinates: [ 0.000000000000000, 0.000000000000000, 0.500000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 6
coordinates: [ 0.500000000000000, 0.000000000000000, 0.500000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 7
coordinates: [ 0.000000000000000, 0.500000000000000, 0.500000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 8
coordinates: [ 0.500000000000000, 0.500000000000000, 0.500000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 9
coordinates: [ 0.000000000000000, 0.250000000000000, 0.250000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 10
coordinates: [ 0.500000000000000, 0.250000000000000, 0.250000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 11
coordinates: [ 0.000000000000000, 0.750000000000000, 0.250000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 12
coordinates: [ 0.500000000000000, 0.750000000000000, 0.250000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 13
coordinates: [ 0.000000000000000, 0.250000000000000, 0.750000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 14
coordinates: [ 0.500000000000000, 0.250000000000000, 0.750000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 15
coordinates: [ 0.000000000000000, 0.750000000000000, 0.750000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 16
coordinates: [ 0.500000000000000, 0.750000000000000, 0.750000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 17
coordinates: [ 0.250000000000000, 0.000000000000000, 0.250000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 18
coordinates: [ 0.750000000000000, 0.000000000000000, 0.250000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 19
coordinates: [ 0.250000000000000, 0.500000000000000, 0.250000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 20
coordinates: [ 0.750000000000000, 0.500000000000000, 0.250000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 21
coordinates: [ 0.250000000000000, 0.000000000000000, 0.750000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 22
coordinates: [ 0.750000000000000, 0.000000000000000, 0.750000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 23
coordinates: [ 0.250000000000000, 0.500000000000000, 0.750000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 24
coordinates: [ 0.750000000000000, 0.500000000000000, 0.750000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 25
coordinates: [ 0.250000000000000, 0.250000000000000, 0.000000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 26
coordinates: [ 0.750000000000000, 0.250000000000000, 0.000000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 27
coordinates: [ 0.250000000000000, 0.750000000000000, 0.000000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 28
coordinates: [ 0.750000000000000, 0.750000000000000, 0.000000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 29
coordinates: [ 0.250000000000000, 0.250000000000000, 0.500000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 30
coordinates: [ 0.750000000000000, 0.250000000000000, 0.500000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 31
coordinates: [ 0.250000000000000, 0.750000000000000, 0.500000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Pb # 32
coordinates: [ 0.750000000000000, 0.750000000000000, 0.500000000000000 ]
mass: 207.200000
reduced_to: 1
- symbol: Te # 33
coordinates: [ 0.250000000000000, 0.250000000000000, 0.250000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 34
coordinates: [ 0.750000000000000, 0.250000000000000, 0.250000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 35
coordinates: [ 0.250000000000000, 0.750000000000000, 0.250000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 36
coordinates: [ 0.750000000000000, 0.750000000000000, 0.250000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 37
coordinates: [ 0.250000000000000, 0.250000000000000, 0.750000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 38
coordinates: [ 0.750000000000000, 0.250000000000000, 0.750000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 39
coordinates: [ 0.250000000000000, 0.750000000000000, 0.750000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 40
coordinates: [ 0.750000000000000, 0.750000000000000, 0.750000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 41
coordinates: [ 0.250000000000000, 0.000000000000000, 0.000000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 42
coordinates: [ 0.750000000000000, 0.000000000000000, 0.000000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 43
coordinates: [ 0.250000000000000, 0.500000000000000, 0.000000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 44
coordinates: [ 0.750000000000000, 0.500000000000000, 0.000000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 45
coordinates: [ 0.250000000000000, 0.000000000000000, 0.500000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 46
coordinates: [ 0.750000000000000, 0.000000000000000, 0.500000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 47
coordinates: [ 0.250000000000000, 0.500000000000000, 0.500000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 48
coordinates: [ 0.750000000000000, 0.500000000000000, 0.500000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 49
coordinates: [ 0.000000000000000, 0.250000000000000, 0.000000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 50
coordinates: [ 0.500000000000000, 0.250000000000000, 0.000000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 51
coordinates: [ 0.000000000000000, 0.750000000000000, 0.000000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 52
coordinates: [ 0.500000000000000, 0.750000000000000, 0.000000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 53
coordinates: [ 0.000000000000000, 0.250000000000000, 0.500000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 54
coordinates: [ 0.500000000000000, 0.250000000000000, 0.500000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 55
coordinates: [ 0.000000000000000, 0.750000000000000, 0.500000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 56
coordinates: [ 0.500000000000000, 0.750000000000000, 0.500000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 57
coordinates: [ 0.000000000000000, 0.000000000000000, 0.250000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 58
coordinates: [ 0.500000000000000, 0.000000000000000, 0.250000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 59
coordinates: [ 0.000000000000000, 0.500000000000000, 0.250000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 60
coordinates: [ 0.500000000000000, 0.500000000000000, 0.250000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 61
coordinates: [ 0.000000000000000, 0.000000000000000, 0.750000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 62
coordinates: [ 0.500000000000000, 0.000000000000000, 0.750000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 63
coordinates: [ 0.000000000000000, 0.500000000000000, 0.750000000000000 ]
mass: 127.600000
reduced_to: 33
- symbol: Te # 64
coordinates: [ 0.500000000000000, 0.500000000000000, 0.750000000000000 ]
mass: 127.600000
reduced_to: 33

displacements:
- atom: 1
displacement:
[ 0.0300000000000000, 0.0000000000000000, 0.0000000000000000 ]
- atom: 1
displacement:
[ -0.0300000000000000, 0.0000000000000000, 0.0000000000000000 ]
- atom: 33
displacement:
[ 0.0300000000000000, 0.0000000000000000, 0.0000000000000000 ]
- atom: 33
displacement:
[ -0.0300000000000000, 0.0000000000000000, 0.0000000000000000 ]
85 changes: 85 additions & 0 deletions example/PbTe/velph-tmpl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
[init.options]
max_num_atoms = 600
phono3py_max_num_atoms = 100

[vasp.incar]
encut = 400
ncore = 4
gga = "PS"

[vasp.relax.kpoints]
mesh = [8, 8, 8]
shift = [0.5, 0.5, 0.5]

[vasp.nac.kpoints]
mesh = [16, 16, 16]

[vasp.el_bands.kpoints]
mesh = [16, 16, 16]
[vasp.el_bands.kpoints_opt]
line = 51
[vasp.el_bands.kpoints_dense]
mesh = [32, 32, 32]

[vasp.phelel.incar]
kpar = 2
ediff = 1e-7
ncore = 8
[vasp.phelel.kpoints]
mesh = [2, 2, 2]
shift = [0.5, 0.5, 0.5]
[vasp.phelel.scheduler]
scheduler_name = "custom"
scheduler_template = '''#!/bin/bash
#QSUB2 core 192
#QSUB2 mpi 192
#QSUB2 smp 1
#QSUB2 wtime 48:00:00
#PBS -N {job_name}
cd $PBS_O_WORKDIR
{prepend_text}
{mpirun_command} {vasp_binary}
{append_text}
'''
job_name = "PbTe"
mpirun_command = "mpijob"
vasp_binary = "/home/togo/src/vasp-tmp1-atztogo/bin/vasp_std"
prepend_text = '''
. /etc/profile.d/modules.sh
module load comp3h
module load hdf5/1.14.3-inteloneapi22u3
'''
append_text = ""

[vasp.phono3py.incar]
kpar = 2
addgrid = true
[vasp.phono3py.kpoints]
mesh = [4, 4, 4]
shift = [0.5, 0.5, 0.5]
[vasp.phono3py.scheduler]
pe = "mpi* 48"

[vasp.phono3py.phonon.incar]
kpar = 2
addgrid = true
[vasp.phono3py.phonon.kpoints]
mesh = [2, 2, 2]
shift = [0.5, 0.5, 0.5]

[vasp.transport.incar]
kpar = 6
[vasp.transport.scheduler]
pe = "mpi* 144"

[scheduler]
scheduler_name = "sge"
job_name = "PbTe"
mpirun_command = "mpirun"
vasp_binary = "/home/togo/phelel/vasp-tmp1-atztogo/bin/vasp_std"
pe = "vienna 32"
prepend_text = '''
source /opt/intel/oneapi/setvars.sh --config="/home/togo/.oneapi-config"
'''
append_text = ""
210 changes: 128 additions & 82 deletions src/phelel/api_phelel.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/phelel/base/Dij_qij.py
Original file line number Diff line number Diff line change
@@ -277,7 +277,7 @@ def _setup(self):
else:
atoms = self._atom_indices_in
self._atom_indices = np.array(
[i for i in atoms if i in equiv_atoms], dtype="int_"
[i for i in atoms if i in equiv_atoms], dtype="long"
)
sitesym_selected_indices = [
i for i, eq_atom in enumerate(equiv_atoms) if eq_atom in self._atom_indices
@@ -451,7 +451,7 @@ class DDijQij:
np.unique(atom_indices given at __init__). If None, all atoms in
supercell.
shape=(len(atom_indices),)
dtype='int_'
dtype='long'
"""

@@ -482,9 +482,9 @@ def __init__(
self._verbose = verbose

if atom_indices is None:
self.atom_indices = np.arange(len(self._supercell), dtype="int_")
self.atom_indices = np.arange(len(self._supercell), dtype="long")
else:
self.atom_indices = np.array(np.unique(atom_indices), dtype="int_")
self.atom_indices = np.array(np.unique(atom_indices), dtype="long")
if symmetry is None:
self.symmetry = Symmetry(supercell)
else:
44 changes: 22 additions & 22 deletions src/phelel/base/local_potential.py
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ class LocalPotentialInterpolationNUFFT:
----------
p2s_matrix : ndarray
Transformation matrix to supercell from primitive cell
dtype='int_'
dtype='long'
shape=(3,3)
grid_points : ndarray
Points to be used to compute <psi|dV_loc|psi'> given as
@@ -120,7 +120,7 @@ class LocalPotentialInterpolationNUFFT:
shape=(prod(fft_mesh)*det(p2s_matrix), 3)
lattice_points : ndarray
Lattice points in supercell in primitive cell coordinates
dtype='int_'
dtype='long'
shape=(det(supercell_matrxi), 3)
dVdu : ndarray
Displacement derivative of local potential in supercell interpolated on
@@ -130,7 +130,7 @@ class LocalPotentialInterpolationNUFFT:
atom_indices_returned : ndarray
Atom indices in supercell where dV will be computed. If those indices
don't belong to symmetrically equivalent atoms to the dispalced atom.
dtype='int_', shape=(atom_indices,)
dtype='long', shape=(atom_indices,)
dVs : list of DeltaLocalPotential
This is given from DLocalPotential.run().
@@ -153,11 +153,11 @@ def __init__(
----------
fft_mesh : array_like
Mesh numbers for primitive cell
dtype='int_'
dtype='long'
shape=(3,)
p2s_matrix : array_like
Supercell matrix relative to primitve cell
dtype='int_'
dtype='long'
shape=(3,3)
supercell : PhonopyAtoms
Perfect supercell
@@ -179,7 +179,7 @@ def __init__(
##########
# Inputs #
##########
self._fft_mesh = np.array(fft_mesh, dtype="int_")
self._fft_mesh = np.array(fft_mesh, dtype="long")
self._verbose = verbose
self._supercell = supercell
self._symmetry = symmetry
@@ -196,7 +196,7 @@ def __init__(
##########
# Public #
##########
self._p2s_matrix = np.array(p2s_matrix, dtype="int_", order="C")
self._p2s_matrix = np.array(p2s_matrix, dtype="long", order="C")
(self._grid_points, self._lattice_points) = get_grid_points(
fft_mesh, self._p2s_matrix
)
@@ -327,7 +327,7 @@ def delta_Vs(self, delta_Vs: list[DeltaLocalPotential]):
else:
atoms = self._atom_indices_in
self._atom_indices_returned = np.array(
[i for i in atoms if i in equiv_atoms], dtype="int_"
[i for i in atoms if i in equiv_atoms], dtype="long"
)
sitesym_selected_indices = [
i
@@ -493,7 +493,7 @@ class DLocalPotential:
----------
p2s_matrix : ndarray
Transformation matrix to supercell from primitive cell.
dtype='int_', shape=(3,3)
dtype='long', shape=(3,3)
grid_points : ndarray
Points to be used to compute <psi|dV_loc|psi'> given as
coordinates of supercell. Coordinates are given as
@@ -504,7 +504,7 @@ class DLocalPotential:
shape=(prod(fft_mesh)*det(p2s_matrix), 3)
lattice_points : ndarray
Lattice points in supercell in primitive cell coordinates.
dtype='int_', shape=(det(supercell_matrxi), 3)
dtype='long', shape=(det(supercell_matrxi), 3)
supercell : PhonopyAtoms
Supercell.
symmetry : Symmetry
@@ -517,10 +517,10 @@ class DLocalPotential:
Atom indices in supercell where dV is computed. This is made as
np.unique(atom_indices given at __init__). If None, all atoms in
supercell.
shape=(len(atom_indices),), dtype='int_'
shape=(len(atom_indices),), dtype='long'
fft_mesh : array_like
Mesh numbers for primitive cell.
dtype='int_', shape=(3,)
dtype='long', shape=(3,)
"""

@@ -541,10 +541,10 @@ def __init__(
----------
fft_mesh : array_like
Mesh numbers for primitive cell.
dtype='int_', shape=(3,)
dtype='long', shape=(3,)
p2s_matrix : ndarray or 2d list
Supercell matrix relative to primitve cell.
dtype='int_', shape=(3,3)
dtype='long', shape=(3,3)
supercell : PhonopyAtoms
Supercell.
symmetry : Symmetry, optional
@@ -569,9 +569,9 @@ def __init__(
self._fft_mesh = fft_mesh
self._p2s_matrix = p2s_matrix
if atom_indices is None:
self._atom_indices = np.arange(len(self._supercell), dtype="int_")
self._atom_indices = np.arange(len(self._supercell), dtype="long")
else:
self._atom_indices = np.array(np.unique(atom_indices), dtype="int_")
self._atom_indices = np.array(np.unique(atom_indices), dtype="long")
if symmetry is None:
self._symmetry = Symmetry(self._supercell)
else:
@@ -644,7 +644,7 @@ def lattice_points(self):
def lattice_points(self, lattice_points: np.ndarray):
multi = determinant(self.p2s_matrix)
if lattice_points.shape == (multi, 3):
self._lattice_points = np.array(lattice_points, dtype="int_", order="C")
self._lattice_points = np.array(lattice_points, dtype="long", order="C")
else:
raise RuntimeError(
"Array shape disagreement is found, %s!=%s."
@@ -862,11 +862,11 @@ def collect_site_symmetry_operations(
Sets of indices of symmetry operations. Each set contains symmetry
operations that send the displaced atom to specific one of equivalent
atoms.
dtype='int_'
dtype='long'
shape=(equiv_atoms, site_syms)
equiv_atoms : ndarray
Indices of symmetrically equivalent atoms
dtype='int_'
dtype='long'
shape=(equiv_atoms,)
"""
@@ -881,15 +881,15 @@ def collect_site_symmetry_operations(
for i, x in enumerate(map_to_indep_atoms)
if map_to_indep_atoms[disp_atom] == x
],
dtype="int_",
dtype="long",
)
ops_sets = []
for i_atom in equiv_atoms:
isyms = np.where(perms == i_atom)[0]
if len(isyms) > 0:
ops_sets.append(isyms)

return np.array(ops_sets, dtype="int_", order="C"), equiv_atoms
return np.array(ops_sets, dtype="long", order="C"), equiv_atoms


def get_displacements_with_rotations(
@@ -993,7 +993,7 @@ def get_grid_points(
shape=(prod(fft_mesh)*det(p2s_matrix), 3)
lattice_points : ndarray
Lattice points in supercell in primitive cell coordinates
dtype='int_'
dtype='long'
shape=(det(p2s_matrix), 3)
"""
4 changes: 2 additions & 2 deletions src/phelel/cui/load.py
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ def load(
FFT mesh numbers for primitive cell used for generating local potential
derivative interpolation grid. This has to be set to run displacement
derivative calculations not only dV/du, but also dDij/du. Default is None.
dtype='int_', shape=(3,)
dtype='long', shape=(3,)
unitcell : PhonopyAtoms, optional
Input unit cell. Default is None.
supercell : PhonopyAtoms, optional
@@ -143,7 +143,7 @@ def load(
if phonon_dataset:
phelel.phonon_dataset = phonon_dataset
elif dataset:
phelel.phonon_dataset = {k: v for k, v in dataset.items()}
phelel.dataset = {k: v for k, v in dataset.items()}
if _nac_params:
phelel.nac_params = _nac_params

4 changes: 1 addition & 3 deletions src/phelel/cui/phelel_script.py
Original file line number Diff line number Diff line change
@@ -250,9 +250,7 @@ def main(**argparse_control):
phe_yml.read(filename)

phelel.dataset = phe_yml.dataset
if phe_yml.phonon_dataset is None:
phelel.phonon_dataset = phe_yml.dataset
else:
if phe_yml.phonon_dataset is not None:
phelel.phonon_dataset = phe_yml.phonon_dataset

if pathlib.Path("BORN").exists() or phe_yml.nac_params:
38 changes: 19 additions & 19 deletions src/phelel/file_IO.py
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@ def read_phelel_params_hdf5(
np.linalg.inv(f["supercell_lattice"][:]) @ f["primitive_lattice"][:]
)
p2s_mat_float = np.linalg.inv(pmat)
p2s_matrix = np.rint(p2s_mat_float).astype("int_")
p2s_matrix = np.rint(p2s_mat_float).astype("long")
assert (abs(p2s_matrix - p2s_mat_float) < 1e-5).all()

if log_level:
@@ -222,7 +222,7 @@ def _add_datasets(
w.create_dataset("Rij", data=cmplx2real(Rij))
if supercell_matrix is not None:
w.create_dataset(
"supercell_matrix", data=np.array(supercell_matrix, dtype="int_", order="C")
"supercell_matrix", data=np.array(supercell_matrix, dtype="long", order="C")
)
if primitive_matrix is not None:
w.create_dataset(
@@ -239,24 +239,24 @@ def _add_datasets(
data=np.array(primitive.scaled_positions, dtype="double", order="C"),
)
w.create_dataset(
"primitive_numbers", data=np.array(primitive.numbers, dtype="int_")
"primitive_numbers", data=np.array(primitive.numbers, dtype="long")
)
w.create_dataset(
"primitive_masses", data=np.array(primitive.masses, dtype="double")
)
p2s_vectors, p2s_multiplicities = _get_smallest_vectors(primitive)
w.create_dataset("p2s_map", data=np.array(primitive.p2s_map, dtype="int_"))
w.create_dataset("s2p_map", data=np.array(primitive.s2p_map, dtype="int_"))
w.create_dataset("p2s_map", data=np.array(primitive.p2s_map, dtype="long"))
w.create_dataset("s2p_map", data=np.array(primitive.s2p_map, dtype="long"))
w.create_dataset("shortest_vectors", data=np.array(p2s_vectors, dtype="double"))
w.create_dataset(
"shortest_vector_multiplicities",
data=np.array(p2s_multiplicities, dtype="int_"),
data=np.array(p2s_multiplicities, dtype="long"),
)
if atom_indices_in_derivatives is not None:
if not np.array_equal(atom_indices_in_derivatives, primitive.p2s_map):
w.create_dataset(
"atom_indices_in_derivatives",
data=np.array(atom_indices_in_derivatives, dtype="int_"),
data=np.array(atom_indices_in_derivatives, dtype="long"),
)
if unitcell is not None:
w.create_dataset(
@@ -268,7 +268,7 @@ def _add_datasets(
data=np.array(unitcell.scaled_positions, dtype="double", order="C"),
)
w.create_dataset(
"unitcell_numbers", data=np.array(unitcell.numbers, dtype="int_")
"unitcell_numbers", data=np.array(unitcell.numbers, dtype="long")
)
w.create_dataset(
"unitcell_masses", data=np.array(unitcell.masses, dtype="double")
@@ -283,7 +283,7 @@ def _add_datasets(
data=np.array(supercell.scaled_positions, dtype="double", order="C"),
)
w.create_dataset(
"supercell_numbers", data=np.array(supercell.numbers, dtype="int_")
"supercell_numbers", data=np.array(supercell.numbers, dtype="long")
)
w.create_dataset(
"supercell_masses", data=np.array(supercell.masses, dtype="double")
@@ -292,7 +292,7 @@ def _add_datasets(
if "first_atoms" in disp_dataset:
atom_indices = [d["number"] for d in disp_dataset["first_atoms"]]
w.create_dataset(
"displacements_atom_indices", data=np.array(atom_indices, dtype="int_")
"displacements_atom_indices", data=np.array(atom_indices, dtype="long")
)
disps = [d["displacement"] for d in disp_dataset["first_atoms"]]
w.create_dataset(
@@ -305,25 +305,25 @@ def _add_datasets(
if phonon_supercell_matrix is not None:
w.create_dataset(
"phonon_supercell_matrix",
data=np.array(phonon_supercell_matrix, dtype="int_", order="C"),
data=np.array(phonon_supercell_matrix, dtype="long", order="C"),
)
if phonon_primitive is not None:
p2s_vectors, p2s_multiplicities = _get_smallest_vectors(phonon_primitive)
w.create_dataset(
"phonon_p2s_map", data=np.array(phonon_primitive.p2s_map, dtype="int_")
"phonon_p2s_map", data=np.array(phonon_primitive.p2s_map, dtype="long")
)
w.create_dataset(
"phonon_s2p_map", data=np.array(phonon_primitive.s2p_map, dtype="int_")
"phonon_s2p_map", data=np.array(phonon_primitive.s2p_map, dtype="long")
)
w.create_dataset(
"phonon_shortest_vectors", data=np.array(p2s_vectors, dtype="double")
)
w.create_dataset(
"phonon_shortest_vector_multiplicities",
data=np.array(p2s_multiplicities, dtype="int_"),
data=np.array(p2s_multiplicities, dtype="long"),
)
p2s_mat_float = np.linalg.inv(phonon_primitive.primitive_matrix)
p2s_matrix = np.rint(p2s_mat_float).astype("int_")
p2s_matrix = np.rint(p2s_mat_float).astype("long")
assert (abs(p2s_matrix - p2s_mat_float) < 1e-5).all()
lattice_points, _ = get_lattice_points(p2s_matrix)
w.create_dataset("phonon_lattice_point", data=lattice_points)
@@ -338,7 +338,7 @@ def _add_datasets(
)
w.create_dataset(
"phonon_supercell_numbers",
data=np.array(phonon_supercell.numbers, dtype="int_"),
data=np.array(phonon_supercell.numbers, dtype="long"),
)
w.create_dataset(
"phonon_supercell_masses",
@@ -362,18 +362,18 @@ def _add_datasets(
)
w.create_dataset(
"direct_rotations",
data=np.array(symmetry_dataset.rotations, dtype="int_", order="C"),
data=np.array(symmetry_dataset.rotations, dtype="long", order="C"),
)
sym_dataset_dict = vars(symmetry_dataset)
if "number" in sym_dataset_dict: # For non-magnetic case
w.create_dataset(
"spacegroup_number", data=int(symmetry_dataset.number), dtype="int_"
"spacegroup_number", data=int(symmetry_dataset.number), dtype="long"
)
elif "uni_number" in sym_dataset_dict: # For magnetic case
w.create_dataset(
"magnetic_spacegroup_uni_number",
data=int(symmetry_dataset.uni_number),
dtype="int_",
dtype="long",
)


3 changes: 2 additions & 1 deletion src/phelel/interface/phelel_yaml.py
Original file line number Diff line number Diff line change
@@ -189,7 +189,8 @@ def _nac_yaml_lines(self):
This method override PhonopyYaml._nac_yaml_lines.
"""
assert isclose(self._data.primitive, self._data.phonon_primitive)
if self._data.phonon_primitive is not None:
assert isclose(self._data.primitive, self._data.phonon_primitive)
return super()._nac_yaml_lines()

def _displacements_yaml_lines(self, with_forces=False):
42 changes: 27 additions & 15 deletions src/phelel/interface/vasp/derivatives.py
Original file line number Diff line number Diff line change
@@ -8,9 +8,11 @@
from typing import Optional, Union

import numpy as np
from phonopy import Phonopy
from phonopy.file_IO import get_born_parameters
from phonopy.interface.vasp import parse_set_of_forces
from phonopy.structure.atoms import PhonopyAtoms
from phonopy.structure.cells import Primitive
from phonopy.structure.symmetry import Symmetry

from phelel import Phelel
from phelel.api_phelel import PhelelDataset
@@ -58,23 +60,37 @@ def read_files(
else:
_dir_names = phonon_dir_names
vasprun_filenames = _get_vasprun_filenames(_dir_names, log_level=log_level)

if phelel.phonon_supercell_matrix:
supercell = phelel.phonon_supercell
else:
supercell = phelel.supercell
forces = read_forces_from_vasprunxmls(
vasprun_filenames,
phelel.phonon,
supercell,
subtract_rfs=subtract_rfs,
log_level=log_level,
)

if forces[0].shape[0] != len(phelel.phonon_supercell):
if forces[0].shape[0] != len(supercell):
raise ValueError(
"Number of ions in the phonon supercell is different from the number of "
"atoms in the vasprun.xml file."
)

nac_params = _read_born(phelel.phonon)
phelel.phonon.forces = forces
if phelel.phonon_supercell_matrix is None:
phelel.forces = forces
else:
phelel.phonon.forces = forces

nac_params = _read_born(
phelel.primitive, phelel.primitive_symmetry, log_level=log_level
)
if nac_params:
phelel.phonon.nac_params = nac_params
phelel.nac_params = nac_params
if phelel.phonon_supercell_matrix is not None:
phelel.phonon.nac_params = nac_params

return PhelelDataset(
local_potentials=loc_pots,
Dijs=Dijs,
@@ -138,14 +154,12 @@ def read_Rij(dir_name, inwap_per):

def read_forces_from_vasprunxmls(
vasprun_filenames: Union[list, tuple],
phonon: Phonopy,
supercell: PhonopyAtoms,
subtract_rfs=False,
log_level=0,
):
"""Read forces from vasprun.xml's and read NAC params from BORN."""
calc_dataset = parse_set_of_forces(
len(phonon.supercell), vasprun_filenames, verbose=False
)
calc_dataset = parse_set_of_forces(len(supercell), vasprun_filenames, verbose=False)
forces = calc_dataset["forces"]

if subtract_rfs:
@@ -171,12 +185,10 @@ def _get_vasprun_filenames(dir_names, log_level=0):
return vasprun_filenames


def _read_born(phonon: Phonopy, log_level=0):
def _read_born(primitive: Primitive, primitive_symmetry: Symmetry, log_level: int = 0):
if pathlib.Path("BORN").exists():
with open("BORN", "r") as f:
nac_params = get_born_parameters(
f, phonon.primitive, phonon.primitive_symmetry
)
nac_params = get_born_parameters(f, primitive, primitive_symmetry)
if log_level:
print('"BORN" was read.')
return nac_params
@@ -188,7 +200,7 @@ def _get_datasets(phelel: Phelel) -> tuple:
"""Return inwap dataset and phonopy dataset."""
if "first_atoms" in phelel.dataset:
dataset = phelel.dataset
if "first_atoms" in phelel.phonon_dataset:
if phelel.phonon_supercell_matrix and "first_atoms" in phelel.phonon_dataset:
phonon_dataset = phelel.phonon_dataset
else:
phonon_dataset = dataset
6 changes: 1 addition & 5 deletions test/cui/test_phelel_cui.py
Original file line number Diff line number Diff line change
@@ -124,8 +124,6 @@ def test_phelel_script_create_displacements(is_plusminus_displacements: bool):
"phelel_disp.yaml",
"SPOSCAR",
"POSCAR-002",
"SPOSCAR_PH",
"POSCAR_PH-002",
)
for created_filename in ("POSCAR-003", "POSCAR_PH-003"):
file_path = pathlib.Path(cwd_called / created_filename)
@@ -135,10 +133,8 @@ def test_phelel_script_create_displacements(is_plusminus_displacements: bool):
"phelel_disp.yaml",
"SPOSCAR",
"POSCAR-001",
"SPOSCAR_PH",
"POSCAR_PH-001",
)
for created_filename in ("POSCAR-002", "POSCAR_PH-002"):
for created_filename in ("POSCAR-002",):
file_path = pathlib.Path(cwd_called / created_filename)
assert not file_path.exists()

1 change: 0 additions & 1 deletion test/interface/test_phelel_yaml.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ def test_PhelelYaml_get_yaml_lines():
assert isclose(phe_yml.primitive, phe_yml_test.primitive)
assert isclose(phe_yml.unitcell, phe_yml_test.unitcell)
assert isclose(phe_yml.supercell, phe_yml_test.supercell)
assert isclose(phe_yml.phonon_supercell, phe_yml_test.phonon_supercell)
assert phe_yml.version == phe_yml_test.version
np.testing.assert_array_equal(
phe_yml.supercell_matrix, phe_yml_test.supercell_matrix
3 changes: 1 addition & 2 deletions test/interface/vasp/test_derivatives.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ def test_read_forces_from_vasprunxmls_NaCl111(phelel_empty_NaCl111: Phelel):
]
forces = read_forces_from_vasprunxmls(
filenames,
phe.phonon,
phe.supercell,
subtract_rfs=True,
log_level=0,
)
@@ -103,5 +103,4 @@ def _get_phelel_C111(phelel_yaml_filename: str) -> Phelel:
log_level=1,
)
phelel.dataset = phe_yml.dataset
phelel.phonon.dataset = phe_yml.dataset
return phelel
56 changes: 0 additions & 56 deletions test/phelel_disp_NaCl111.yaml
Original file line number Diff line number Diff line change
@@ -128,62 +128,6 @@ supercell:
mass: 35.453000
reduced_to: 5

phonon_primitive_cell:
lattice:
- [ 0.000000000000000, 2.845150738087836, 2.845150738087836 ] # a
- [ 2.845150738087836, 0.000000000000000, 2.845150738087836 ] # b
- [ 2.845150738087836, 2.845150738087836, 0.000000000000000 ] # c
points:
- symbol: Na # 1
coordinates: [ 0.000000000000000, 0.000000000000000, 0.000000000000000 ]
mass: 22.989769
- symbol: Cl # 2
coordinates: [ 0.500000000000000, 0.500000000000000, 0.500000000000000 ]
mass: 35.453000
reciprocal_lattice: # without 2pi
- [ -0.175737613233118, 0.175737613233118, 0.175737613233118 ] # a*
- [ 0.175737613233118, -0.175737613233118, 0.175737613233118 ] # b*
- [ 0.175737613233118, 0.175737613233118, -0.175737613233118 ] # c*

phonon_supercell:
lattice:
- [ 5.690301476175671, 0.000000000000000, 0.000000000000000 ] # a
- [ 0.000000000000000, 5.690301476175671, 0.000000000000000 ] # b
- [ 0.000000000000000, 0.000000000000000, 5.690301476175671 ] # c
points:
- symbol: Na # 1
coordinates: [ 0.000000000000000, 0.000000000000000, 0.000000000000000 ]
mass: 22.989769
reduced_to: 1
- symbol: Na # 2
coordinates: [ 0.000000000000000, 0.500000000000000, 0.500000000000000 ]
mass: 22.989769
reduced_to: 1
- symbol: Na # 3
coordinates: [ 0.500000000000000, 0.000000000000000, 0.500000000000000 ]
mass: 22.989769
reduced_to: 1
- symbol: Na # 4
coordinates: [ 0.500000000000000, 0.500000000000000, 0.000000000000000 ]
mass: 22.989769
reduced_to: 1
- symbol: Cl # 5
coordinates: [ 0.500000000000000, 0.500000000000000, 0.500000000000000 ]
mass: 35.453000
reduced_to: 5
- symbol: Cl # 6
coordinates: [ 0.500000000000000, 0.000000000000000, 0.000000000000000 ]
mass: 35.453000
reduced_to: 5
- symbol: Cl # 7
coordinates: [ 0.000000000000000, 0.500000000000000, 0.000000000000000 ]
mass: 35.453000
reduced_to: 5
- symbol: Cl # 8
coordinates: [ 0.000000000000000, 0.000000000000000, 0.500000000000000 ]
mass: 35.453000
reduced_to: 5

displacements:
- atom: 1
displacement:

0 comments on commit 86467bc

Please sign in to comment.