mirror of https://github.com/phonopy/phono3py.git
Added phono3py-load script like phonopy-load script in phonopy
This commit is contained in:
parent
c3964a200d
commit
35bf8356a0
|
@ -44,7 +44,8 @@ from phono3py.file_IO import (
|
|||
parse_FORCES_FC3, read_fc3_from_hdf5, read_fc2_from_hdf5,
|
||||
write_fc3_to_hdf5, write_fc2_to_hdf5, get_length_of_first_line)
|
||||
from phono3py.cui.show_log import (
|
||||
show_phono3py_force_constants_settings, print_error, file_exists)
|
||||
show_phono3py_force_constants_settings)
|
||||
from phonopy.cui.phonopy_script import print_error, file_exists
|
||||
from phono3py.phonon3.fc3 import (
|
||||
set_permutation_symmetry_fc3, set_translational_invariance_fc3)
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ def load(phono3py_yaml=None, # phono3py.yaml-like must be the first argument.
|
|||
fc3_filename=None,
|
||||
fc2_filename=None,
|
||||
fc_calculator=None,
|
||||
fc_calculator_options=None,
|
||||
factor=None,
|
||||
frequency_scale_factor=None,
|
||||
produce_fc=True,
|
||||
|
@ -197,6 +198,11 @@ def load(phono3py_yaml=None, # phono3py.yaml-like must be the first argument.
|
|||
second-order force constants. Default is None.
|
||||
fc_calculator : str, optional
|
||||
Force constants calculator. Currently only 'alm'. Default is None.
|
||||
fc_calculator_options : str, optional
|
||||
Optional parameters that are passed to the external fc-calculator.
|
||||
This is given as one text string. How to parse this depends on the
|
||||
fc-calculator. For alm, each parameter is splitted by comma ',',
|
||||
and each set of key and value pair is written in 'key = value'.
|
||||
factor : float, optional
|
||||
Phonon frequency unit conversion factor. Unless specified, default
|
||||
unit conversion factor for each calculator is used.
|
||||
|
@ -300,7 +306,7 @@ def load(phono3py_yaml=None, # phono3py.yaml-like must be the first argument.
|
|||
units['nac_factor'],
|
||||
log_level=log_level)
|
||||
|
||||
_set_dataset_and_force_constants(
|
||||
set_dataset_and_force_constants(
|
||||
ph3py,
|
||||
units,
|
||||
dataset=None,
|
||||
|
@ -309,6 +315,7 @@ def load(phono3py_yaml=None, # phono3py.yaml-like must be the first argument.
|
|||
forces_fc3_filename=forces_fc3_filename,
|
||||
forces_fc2_filename=forces_fc2_filename,
|
||||
fc_calculator=fc_calculator,
|
||||
fc_calculator_options=fc_calculator_options,
|
||||
produce_fc=produce_fc,
|
||||
symmetrize_fc=symmetrize_fc,
|
||||
is_compact_fc=is_compact_fc,
|
||||
|
@ -321,7 +328,7 @@ def load(phono3py_yaml=None, # phono3py.yaml-like must be the first argument.
|
|||
return ph3py
|
||||
|
||||
|
||||
def _set_dataset_and_force_constants(
|
||||
def set_dataset_and_force_constants(
|
||||
ph3py,
|
||||
units,
|
||||
dataset=None,
|
||||
|
|
|
@ -36,7 +36,9 @@ import sys
|
|||
from phonopy.cui.phonopy_argparse import fix_deprecated_option_names
|
||||
|
||||
|
||||
def get_parser():
|
||||
def get_parser(fc_symmetry=False,
|
||||
is_nac=False,
|
||||
load_phono3py_yaml=False):
|
||||
deprecated = fix_deprecated_option_names(sys.argv)
|
||||
import argparse
|
||||
from phonopy.interface.calculator import add_arguments_of_calculators
|
||||
|
@ -76,9 +78,10 @@ def get_parser():
|
|||
"--br", "--bterta", dest="is_bterta", action="store_true",
|
||||
default=False,
|
||||
help="Calculate thermal conductivity in BTE-RTA")
|
||||
parser.add_argument(
|
||||
"-c", "--cell", dest="cell_filename", metavar="FILE", default=None,
|
||||
help="Read unit cell")
|
||||
if not load_phono3py_yaml:
|
||||
parser.add_argument(
|
||||
"-c", "--cell", dest="cell_filename", metavar="FILE", default=None,
|
||||
help="Read unit cell")
|
||||
parser.add_argument(
|
||||
"--cf2", "--create-f2", dest="forces_fc2", nargs='+', default=None,
|
||||
help="Create FORCES_FC2")
|
||||
|
@ -149,10 +152,11 @@ def get_parser():
|
|||
dest="fc_calculator_options", default=None,
|
||||
help=("Options for force constants calculator as comma separated "
|
||||
"string with the style of key = values"))
|
||||
parser.add_argument(
|
||||
"--fc-symmetry", "--sym-fc", dest="fc_symmetry", action="store_true",
|
||||
default=False,
|
||||
help="Symmetrize force constants")
|
||||
if not fc_symmetry:
|
||||
parser.add_argument(
|
||||
"--fc-symmetry", "--sym-fc", dest="fc_symmetry",
|
||||
action="store_true", default=False,
|
||||
help="Symmetrize force constants")
|
||||
parser.add_argument(
|
||||
"--freq-scale", dest="frequency_scale_factor", type=float,
|
||||
default=None,
|
||||
|
@ -236,12 +240,18 @@ def get_parser():
|
|||
"--mv", "--mass-variances", nargs='+', dest="mass_variances",
|
||||
default=None,
|
||||
help="Mass variance parameters for isotope scattering")
|
||||
parser.add_argument(
|
||||
"--nac", dest="is_nac", action="store_true", default=False,
|
||||
help="Non-analytical term correction")
|
||||
if not is_nac:
|
||||
parser.add_argument(
|
||||
"--nac", dest="is_nac", action="store_true", default=False,
|
||||
help="Non-analytical term correction")
|
||||
parser.add_argument(
|
||||
"--nac-method", dest="nac_method", default=None,
|
||||
help="Non-analytical term correction method: Wang (default) or Gonze")
|
||||
if fc_symmetry:
|
||||
parser.add_argument(
|
||||
"--no-fc-symmetry", "--no-sym-fc",
|
||||
dest="fc_symmetry", action="store_false",
|
||||
default=True, help="Do not symmetrize force constants")
|
||||
parser.add_argument(
|
||||
"--nodiag", dest="is_nodiag", action="store_true", default=False,
|
||||
help="Set displacements parallel to axes")
|
||||
|
@ -252,6 +262,10 @@ def get_parser():
|
|||
parser.add_argument(
|
||||
"--nomeshsym", dest="is_nomeshsym", action="store_true", default=False,
|
||||
help="No symmetrization of triplets is made.")
|
||||
if is_nac:
|
||||
parser.add_argument(
|
||||
"--nonac", dest="is_nac", action="store_false", default=True,
|
||||
help="Non-analytical term correction")
|
||||
parser.add_argument(
|
||||
"--nosym", dest="is_nosym", action="store_true", default=False,
|
||||
help="Symmetry is not imposed.")
|
||||
|
@ -391,8 +405,11 @@ def get_parser():
|
|||
"--write-lbte-solution", dest="write_LBTE_solution",
|
||||
action="store_true", default=False,
|
||||
help="Write direct solution of LBTE to hdf5 files")
|
||||
parser.add_argument(
|
||||
"conf_file", nargs='*',
|
||||
help="Phono3py configure file")
|
||||
if load_phono3py_yaml:
|
||||
parser.add_argument(
|
||||
"filename", nargs='*', help="phono3py.yaml like file")
|
||||
else:
|
||||
parser.add_argument(
|
||||
"filename", nargs='*', help="Phono3py configure file")
|
||||
|
||||
return parser, deprecated
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
|
||||
import sys
|
||||
import numpy as np
|
||||
from phonopy.file_IO import write_FORCE_SETS, parse_FORCE_SETS
|
||||
from phonopy.file_IO import (
|
||||
write_FORCE_SETS, parse_FORCE_SETS, is_file_phonopy_yaml)
|
||||
from phonopy.units import VaspToTHz, Bohr, Hartree
|
||||
from phonopy.cui.collect_cell_info import collect_cell_info
|
||||
from phonopy.cui.create_force_sets import check_number_of_force_files
|
||||
|
@ -44,7 +45,9 @@ from phonopy.interface.calculator import (
|
|||
get_force_sets, get_default_physical_units, get_interface_mode)
|
||||
from phonopy.cui.phonopy_argparse import show_deprecated_option_warnings
|
||||
from phonopy.phonon.band_structure import get_band_qpoints
|
||||
from phonopy.cui.phonopy_script import store_nac_params
|
||||
from phonopy.cui.phonopy_script import (
|
||||
store_nac_params, print_end, print_error, print_error_message,
|
||||
print_version, file_exists, get_fc_calculator_params)
|
||||
from phono3py.version import __version__
|
||||
from phono3py.file_IO import (
|
||||
parse_disp_fc2_yaml, parse_disp_fc3_yaml,
|
||||
|
@ -52,15 +55,13 @@ from phono3py.file_IO import (
|
|||
parse_FORCES_FC2, write_FORCES_FC2, write_FORCES_FC3,
|
||||
get_length_of_first_line)
|
||||
from phono3py.cui.settings import Phono3pyConfParser
|
||||
from phono3py.cui.load import set_dataset_and_force_constants
|
||||
from phono3py import Phono3py, Phono3pyJointDos, Phono3pyIsotope
|
||||
from phono3py.phonon3.gruneisen import run_gruneisen_parameters
|
||||
from phono3py.phonon3.triplets import get_grid_point_from_address
|
||||
from phono3py.cui.phono3py_argparse import get_parser
|
||||
from phono3py.cui.show_log import (print_phono3py, print_version, print_end,
|
||||
print_error, print_error_message,
|
||||
show_general_settings,
|
||||
show_phono3py_settings,
|
||||
show_phono3py_cells, file_exists)
|
||||
from phono3py.cui.show_log import (
|
||||
show_general_settings, show_phono3py_settings, show_phono3py_cells)
|
||||
from phono3py.cui.triplets_info import write_grid_points, show_num_triplets
|
||||
from phono3py.cui.create_supercells import create_phono3py_supercells
|
||||
from phono3py.cui.create_force_constants import create_phono3py_force_constants
|
||||
|
@ -72,6 +73,16 @@ from phono3py.interface.phono3py_yaml import Phono3pyYaml
|
|||
# logging.getLogger("phono3py.phonon3.fc3").setLevel(level=logging.DEBUG)
|
||||
|
||||
|
||||
# AA is created at http://www.network-science.de/ascii/.
|
||||
def print_phono3py():
|
||||
print(""" _ _____
|
||||
_ __ | |__ ___ _ __ ___|___ / _ __ _ _
|
||||
| '_ \| '_ \ / _ \| '_ \ / _ \ |_ \| '_ \| | | |
|
||||
| |_) | | | | (_) | | | | (_) |__) | |_) | |_| |
|
||||
| .__/|_| |_|\___/|_| |_|\___/____/| .__/ \__, |
|
||||
|_| |_| |___/ """)
|
||||
|
||||
|
||||
def finalize_phono3py(phono3py,
|
||||
confs,
|
||||
log_level,
|
||||
|
@ -136,10 +147,10 @@ def get_run_mode(settings):
|
|||
return run_mode
|
||||
|
||||
|
||||
def start_phono3py():
|
||||
def start_phono3py(**argparse_control):
|
||||
"""Parse arguments and set some basic parameters"""
|
||||
|
||||
parser, deprecated = get_parser()
|
||||
parser, deprecated = get_parser(**argparse_control)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Log level
|
||||
|
@ -155,6 +166,8 @@ def start_phono3py():
|
|||
if log_level:
|
||||
print_phono3py()
|
||||
print_version(__version__)
|
||||
if argparse_control.get('load_phono3py_yaml', False):
|
||||
print("Running in phono3py.load mode.")
|
||||
print("Python version %d.%d.%d" % sys.version_info[:3])
|
||||
import phonopy.structure.spglib as spglib
|
||||
print("Spglib version %d.%d.%d" % spglib.get_version())
|
||||
|
@ -165,19 +178,33 @@ def start_phono3py():
|
|||
return args, log_level
|
||||
|
||||
|
||||
def read_phono3py_settings(args, log_level):
|
||||
def read_phono3py_settings(args, argparse_control, log_level):
|
||||
"""Read phono3py settings"""
|
||||
|
||||
if len(args.conf_file) > 0:
|
||||
phono3py_conf = Phono3pyConfParser(filename=args.conf_file[0],
|
||||
args=args)
|
||||
load_phono3py_yaml = argparse_control.get('load_phono3py_yaml', False)
|
||||
|
||||
if len(args.filename) > 0:
|
||||
file_exists(args.filename[0], log_level)
|
||||
if load_phono3py_yaml:
|
||||
phono3py_conf_parser = Phono3pyConfParser(
|
||||
args=args, default_settings=argparse_control)
|
||||
cell_filename = args.filename[0]
|
||||
else:
|
||||
if is_file_phonopy_yaml(args.filename[0], keyword='phono3py'):
|
||||
phono3py_conf_parser = Phono3pyConfParser(args=args)
|
||||
cell_filename = args.filename[0]
|
||||
else:
|
||||
phono3py_conf_parser = Phono3pyConfParser(
|
||||
filename=args.filename[0], args=args)
|
||||
cell_filename = phono3py_conf_parser.settings.cell_filename
|
||||
else:
|
||||
phono3py_conf = Phono3pyConfParser(args=args)
|
||||
phono3py_conf_parser = Phono3pyConfParser(args=args)
|
||||
cell_filename = phono3py_conf_parser.settings.cell_filename
|
||||
|
||||
settings = phono3py_conf.settings
|
||||
confs = phono3py_conf.confs.copy()
|
||||
confs = phono3py_conf_parser.confs.copy()
|
||||
settings = phono3py_conf_parser.settings
|
||||
|
||||
return settings, confs
|
||||
return settings, confs, cell_filename
|
||||
|
||||
|
||||
def create_phono3py_files_then_exit(args, log_level):
|
||||
|
@ -387,7 +414,7 @@ def get_cell_info(settings, cell_filename, symprec, log_level):
|
|||
supercell_matrix=settings.supercell_matrix,
|
||||
primitive_matrix=settings.primitive_matrix,
|
||||
interface_mode=settings.calculator,
|
||||
cell_filename=settings.cell_filename,
|
||||
cell_filename=cell_filename,
|
||||
chemical_symbols=settings.chemical_symbols,
|
||||
phonopy_yaml_cls=Phono3pyYaml,
|
||||
symprec=symprec,
|
||||
|
@ -532,6 +559,35 @@ def init_phono3py(settings,
|
|||
return phono3py, updated_settings
|
||||
|
||||
|
||||
def store_force_constants(phono3py,
|
||||
settings,
|
||||
physical_units,
|
||||
input_filename,
|
||||
output_filename,
|
||||
load_phono3py_yaml,
|
||||
log_level):
|
||||
if load_phono3py_yaml:
|
||||
(fc_calculator,
|
||||
fc_calculator_options) = get_fc_calculator_params(settings)
|
||||
set_dataset_and_force_constants(
|
||||
phono3py,
|
||||
physical_units,
|
||||
fc_calculator=fc_calculator,
|
||||
fc_calculator_options=fc_calculator_options,
|
||||
symmetrize_fc=settings.fc_symmetry,
|
||||
is_compact_fc=settings.is_compact_fc,
|
||||
log_level=log_level)
|
||||
else:
|
||||
create_phono3py_force_constants(
|
||||
phono3py,
|
||||
settings,
|
||||
force_to_eVperA=physical_units['force_to_eVperA'],
|
||||
distance_to_A=physical_units['distance_to_A'],
|
||||
input_filename=input_filename,
|
||||
output_filename=output_filename,
|
||||
log_level=log_level)
|
||||
|
||||
|
||||
def run_gruneisen_then_exit(phono3py, settings, output_filename, log_level):
|
||||
if (settings.mesh_numbers is None and
|
||||
settings.band_paths is None and
|
||||
|
@ -703,8 +759,10 @@ def init_phph_interaction(phono3py,
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
args, log_level = start_phono3py()
|
||||
def main(**argparse_control):
|
||||
load_phono3py_yaml = argparse_control.get('load_phono3py_yaml', False)
|
||||
|
||||
args, log_level = start_phono3py(**argparse_control)
|
||||
interface_mode = get_interface_mode(vars(args))
|
||||
physical_units = get_default_physical_units(interface_mode)
|
||||
(input_filename,
|
||||
|
@ -712,8 +770,8 @@ def main():
|
|||
|
||||
create_phono3py_files_then_exit(args, log_level)
|
||||
|
||||
settings, confs = read_phono3py_settings(args, log_level)
|
||||
cell_filename = settings.cell_filename
|
||||
settings, confs, cell_filename = read_phono3py_settings(
|
||||
args, argparse_control, log_level)
|
||||
|
||||
# Symmetry tolerance. Distance unit depends on interface.
|
||||
if settings.symmetry_tolerance is None:
|
||||
|
@ -831,19 +889,19 @@ def main():
|
|||
cell_info['phonopy_yaml'],
|
||||
unitcell_filename,
|
||||
log_level,
|
||||
nac_factor=Hartree * Bohr)
|
||||
nac_factor=Hartree * Bohr,
|
||||
load_phonopy_yaml=load_phono3py_yaml)
|
||||
|
||||
###################
|
||||
# Force constants #
|
||||
###################
|
||||
create_phono3py_force_constants(
|
||||
phono3py,
|
||||
settings,
|
||||
force_to_eVperA=physical_units['force_to_eVperA'],
|
||||
distance_to_A=physical_units['distance_to_A'],
|
||||
input_filename=input_filename,
|
||||
output_filename=output_filename,
|
||||
log_level=log_level)
|
||||
store_force_constants(phono3py,
|
||||
settings,
|
||||
physical_units,
|
||||
input_filename,
|
||||
output_filename,
|
||||
load_phono3py_yaml,
|
||||
log_level)
|
||||
|
||||
############################################
|
||||
# Phonon Gruneisen parameter and then exit #
|
||||
|
|
|
@ -241,8 +241,8 @@ class Phono3pySettings(Settings):
|
|||
|
||||
|
||||
class Phono3pyConfParser(ConfParser):
|
||||
def __init__(self, filename=None, args=None):
|
||||
self._settings = Phono3pySettings()
|
||||
def __init__(self, filename=None, args=None, default_settings=None):
|
||||
self._settings = Phono3pySettings(default=default_settings)
|
||||
confs = {}
|
||||
if filename is not None:
|
||||
ConfParser.__init__(self, filename=filename)
|
||||
|
|
|
@ -32,63 +32,11 @@
|
|||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import numpy as np
|
||||
from phonopy.structure.cells import print_cell
|
||||
|
||||
|
||||
def file_exists(filename, log_level, is_any=False):
|
||||
if os.path.exists(filename):
|
||||
return True
|
||||
else:
|
||||
if is_any:
|
||||
return False
|
||||
else:
|
||||
error_text = "\"%s\" was not found." % filename
|
||||
print(error_text)
|
||||
if log_level > 0:
|
||||
print_error()
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# AA is created at http://www.network-science.de/ascii/.
|
||||
def print_phono3py():
|
||||
print(""" _ _____
|
||||
_ __ | |__ ___ _ __ ___|___ / _ __ _ _
|
||||
| '_ \| '_ \ / _ \| '_ \ / _ \ |_ \| '_ \| | | |
|
||||
| |_) | | | | (_) | | | | (_) |__) | |_) | |_| |
|
||||
| .__/|_| |_|\___/|_| |_|\___/____/| .__/ \__, |
|
||||
|_| |_| |___/ """)
|
||||
|
||||
|
||||
def print_version(version):
|
||||
print(" " * 42 + "%s" % version)
|
||||
print('')
|
||||
|
||||
|
||||
def print_end():
|
||||
print(""" _
|
||||
___ _ __ __| |
|
||||
/ _ \ '_ \ / _` |
|
||||
| __/ | | | (_| |
|
||||
\___|_| |_|\__,_|
|
||||
""")
|
||||
|
||||
|
||||
def print_error():
|
||||
print(""" ___ _ __ _ __ ___ _ __
|
||||
/ _ \ '__| '__/ _ \| '__|
|
||||
| __/ | | | | (_) | |
|
||||
\___|_| |_| \___/|_|
|
||||
""")
|
||||
|
||||
|
||||
def print_error_message(message):
|
||||
print('')
|
||||
print(message)
|
||||
|
||||
|
||||
def show_general_settings(settings,
|
||||
run_mode,
|
||||
phono3py,
|
||||
|
|
|
@ -39,7 +39,7 @@ import numpy as np
|
|||
class Phono3pyYaml(PhonopyYaml):
|
||||
|
||||
command_name = "phono3py"
|
||||
default_filenames = ("phono3py.yaml", )
|
||||
default_filenames = ("phono3py_disp.yaml", "phono3py.yaml")
|
||||
|
||||
def __init__(self,
|
||||
configuration=None,
|
||||
|
|
|
@ -37,4 +37,7 @@
|
|||
from phono3py.cui.phono3py_script import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
argparse_control = {'fc_symmetry': False,
|
||||
'is_nac': False,
|
||||
'load_phono3py_yaml': False}
|
||||
main(**argparse_control)
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (C) 2020 Atsushi Togo
|
||||
# All rights reserved.
|
||||
#
|
||||
# This file is part of phonopy.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# * Neither the name of the phonopy project nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
from phono3py.cui.phono3py_script import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
argparse_control = {'fc_symmetry': True,
|
||||
'is_nac': True,
|
||||
'load_phono3py_yaml': True}
|
||||
main(**argparse_control)
|
Loading…
Reference in New Issue