Skip to content

Commit

Permalink
Introduce vertical bar symbol for fc-calculator str
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Oct 16, 2022
1 parent f4c26db commit 0ba6cbf
Show file tree
Hide file tree
Showing 6 changed files with 967 additions and 17 deletions.
73 changes: 59 additions & 14 deletions phono3py/api_phono3py.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
from phonopy.interface.fc_calculator import get_fc2
from phonopy.structure.atoms import PhonopyAtoms
from phonopy.structure.cells import (
Primitive,
Supercell,
get_primitive,
get_primitive_matrix,
get_supercell,
Expand Down Expand Up @@ -567,7 +569,7 @@ def dynamical_matrix(self):
return self._interaction.dynamical_matrix

@property
def primitive(self):
def primitive(self) -> Primitive:
"""Return primitive cell.
Primitive
Expand All @@ -586,7 +588,7 @@ def get_primitive(self):
return self.primitive

@property
def unitcell(self):
def unitcell(self) -> PhonopyAtoms:
"""Return Unit cell.
PhonopyAtoms
Expand All @@ -605,7 +607,7 @@ def get_unitcell(self):
return self.unitcell

@property
def supercell(self):
def supercell(self) -> Supercell:
"""Return supercell.
Supercell
Expand All @@ -624,7 +626,7 @@ def get_supercell(self):
return self.supercell

@property
def phonon_supercell(self):
def phonon_supercell(self) -> Supercell:
"""Return supercell for fc2.
Supercell
Expand All @@ -643,7 +645,7 @@ def get_phonon_supercell(self):
return self.phonon_supercell

@property
def phonon_primitive(self):
def phonon_primitive(self) -> Primitive:
"""Return primitive cell for fc2.
Primitive
Expand All @@ -664,7 +666,7 @@ def get_phonon_primitive(self):
return self.phonon_primitive

@property
def symmetry(self):
def symmetry(self) -> Symmetry:
"""Return symmetry of supercell.
Symmetry
Expand All @@ -683,7 +685,7 @@ def get_symmetry(self):
return self.symmetry

@property
def primitive_symmetry(self):
def primitive_symmetry(self) -> Symmetry:
"""Return symmetry of primitive cell.
Symmetry
Expand All @@ -702,7 +704,7 @@ def get_primitive_symmetry(self):
return self.primitive_symmetry

@property
def phonon_supercell_symmetry(self):
def phonon_supercell_symmetry(self) -> Symmetry:
"""Return symmetry of supercell for fc2.
Symmetry
Expand Down Expand Up @@ -1625,15 +1627,19 @@ def produce_fc3(
"""
disp_dataset = self._dataset

if fc_calculator is not None:
fc3_calculator, fc3_calculator_options = self._extract_fc2_fc3_calculators(
fc_calculator, fc_calculator_options, 3
)

if fc3_calculator is not None:
disps, forces = get_displacements_and_forces_fc3(disp_dataset)
fc2, fc3 = get_fc3(
self._supercell,
self._primitive,
disps,
forces,
fc_calculator=fc_calculator,
fc_calculator_options=fc_calculator_options,
fc_calculator=fc3_calculator,
fc_calculator_options=fc3_calculator_options,
is_compact_fc=is_compact_fc,
log_level=self._log_level,
)
Expand Down Expand Up @@ -1711,15 +1717,19 @@ def produce_fc2(
else:
p2s_map = None

if fc_calculator is not None:
fc2_calculator, fc2_calculator_options = self._extract_fc2_fc3_calculators(
fc_calculator, fc_calculator_options, 2
)

if fc2_calculator is not None:
disps, forces = get_displacements_and_forces(disp_dataset)
self._fc2 = get_fc2(
self._phonon_supercell,
self._phonon_primitive,
disps,
forces,
fc_calculator=fc_calculator,
fc_calculator_options=fc_calculator_options,
fc_calculator=fc2_calculator,
fc_calculator_options=fc2_calculator_options,
atom_list=p2s_map,
log_level=self._log_level,
)
Expand Down Expand Up @@ -2558,3 +2568,38 @@ def _init_dynamical_matrix(self):
)
print(" But this frequency is forced to be zero.")
print("=" * 61)

def _extract_fc2_fc3_calculators(self, fc_calculator, fc_calculator_options, order):
"""Extract fc_calculator and fc_calculator_options for fc2 and fc3.
fc_calculator : str
FC calculator. "|" separates fc2 and fc3. First and last
parts separated correspond to fc2 and fc3 calculators, respectively.
fc_calculator_options : str
FC calculator options. "|" separates fc2 and fc3. First and last
parts separated correspond to fc2 and fc3 options, respectively.
order : int = 2 or 3
2 and 3 indicate fc2 and fc3, respectively.
"""
if fc_calculator is not None:
if "|" in fc_calculator:
_fc_calculator = fc_calculator.split("|")[order - 2]
if _fc_calculator == "":
_fc_calculator = None
else:
_fc_calculator = fc_calculator
else:
_fc_calculator = None

if fc_calculator_options is not None:
if "|" in fc_calculator_options:
_fc_calculator_options = fc_calculator_options.split("|")[order - 2]
if _fc_calculator_options == "":
_fc_calculator_options = None
else:
_fc_calculator_options = fc_calculator_options
else:
_fc_calculator_options = None

return _fc_calculator, _fc_calculator_options
2 changes: 1 addition & 1 deletion phono3py/cui/phono3py_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ def main(**argparse_control):
)

if log_level > 1:
show_phono3py_cells(phono3py, settings)
show_phono3py_cells(phono3py)
elif log_level:
print(
"Use -v option to watch primitive cell, unit cell, "
Expand Down
4 changes: 2 additions & 2 deletions phono3py/cui/show_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def show_general_settings(
print(" %s" % v)


def show_phono3py_cells(phono3py: Phono3py, settings):
def show_phono3py_cells(phono3py: Phono3py):
"""Show crystal structures."""
primitive = phono3py.primitive
supercell = phono3py.supercell
Expand All @@ -100,7 +100,7 @@ def show_phono3py_cells(phono3py: Phono3py, settings):
print_cell(primitive)
print("-" * 32 + " supercell " + "-" * 33)
print_cell(supercell, mapping=primitive.s2p_map)
if settings.phonon_supercell_matrix is not None:
if phono3py.phonon_supercell_matrix is not None:
print("-" * 19 + " primitive cell for harmonic phonon " + "-" * 20)
print_cell(phonon_primitive)
print("-" * 21 + " supercell for harmonic phonon " + "-" * 22)
Expand Down
85 changes: 85 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,91 @@ def si_pbesol_iterha_111():
return phonopy.load(yaml_filename, log_level=1, produce_fc=False)


@pytest.fixture(scope="session")
def si_pbesol_111_222_fd(request):
"""Return Phono3py instance of Si 1x1x1.
* with symmetry
* full fc
* use alm if available on test side
"""
yaml_filename = os.path.join(current_dir, "phono3py_params_Si-111-222.yaml")
enable_v2 = request.config.getoption("--v1")
return phono3py.load(
yaml_filename,
store_dense_gp_map=enable_v2,
store_dense_svecs=enable_v2,
log_level=1,
)


@pytest.fixture(scope="session")
def si_pbesol_111_222_alm_fd(request):
"""Return Phono3py instance of Si 1x1x1.
* with symmetry
* full fc
* use alm for fc2 if available on test side
"""
pytest.importorskip("alm")

yaml_filename = os.path.join(current_dir, "phono3py_params_Si-111-222.yaml")
enable_v2 = request.config.getoption("--v1")
return phono3py.load(
yaml_filename,
store_dense_gp_map=enable_v2,
store_dense_svecs=enable_v2,
fc_calculator="alm|",
log_level=1,
)


@pytest.fixture(scope="session")
def si_pbesol_111_222_alm(request):
"""Return Phono3py instance of Si 1x1x1.
* with symmetry
* full fc
* use alm if available on test side
"""
pytest.importorskip("alm")

yaml_filename = os.path.join(current_dir, "phono3py_params_Si-111-222.yaml")
enable_v2 = request.config.getoption("--v1")
return phono3py.load(
yaml_filename,
store_dense_gp_map=enable_v2,
store_dense_svecs=enable_v2,
fc_calculator="alm",
log_level=1,
)


@pytest.fixture(scope="session")
def si_pbesol_111_222_fd_alm(request):
"""Return Phono3py instance of Si 1x1x1.
* with symmetry
* full fc
* use alm for fc3 if available on test side
"""
pytest.importorskip("alm")

yaml_filename = os.path.join(current_dir, "phono3py_params_Si-111-222.yaml")
enable_v2 = request.config.getoption("--v1")
return phono3py.load(
yaml_filename,
store_dense_gp_map=enable_v2,
store_dense_svecs=enable_v2,
fc_calculator="|alm",
log_level=1,
)


@pytest.fixture(scope="session")
def nacl_pbe(request):
"""Return Phono3py instance of NaCl 2x2x2.
Expand Down
Loading

0 comments on commit 0ba6cbf

Please sign in to comment.