# Copyright (C) 2015 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.

import numpy as np
from phonopy.units import VaspToTHz
from phono3py.phonon3.triplets import get_grid_point_from_address


def get_phono3py_configurations(settings):
    primitive_matrix = settings.get_primitive_matrix()
    supercell_matrix = settings.get_supercell_matrix()
    phonon_supercell_matrix = settings.get_phonon_supercell_matrix()
    masses = settings.get_masses()
    mesh = settings.get_mesh_numbers()
    mesh_divs = settings.get_mesh_divisors()
    coarse_mesh_shifts = settings.get_coarse_mesh_shifts()
    grid_points = settings.get_grid_points()
    grid_addresses = settings.get_grid_addresses()
    if grid_addresses is not None:
        grid_points = [get_grid_point_from_address(ga, mesh)
                       for ga in grid_addresses]
    band_indices = settings.get_band_indices()

    # Brillouin zone integration: Tetrahedron (default) or smearing method
    sigma = settings.get_sigma()
    if sigma is None:
        sigmas = []
    elif isinstance(sigma, float):
        sigmas = [sigma]
    else:
        sigmas = sigma
    if settings.get_is_tetrahedron_method():
        sigmas = [None] + sigmas
    if len(sigmas) == 0:
        sigmas = [None]

    sigma_cutoff = settings.get_sigma_cutoff_width()

    if settings.get_temperatures() is None:
        if settings.get_is_joint_dos():
            temperature_points = None
            temperatures = None
        else:
            t_max = settings.get_max_temperature()
            t_min = settings.get_min_temperature()
            t_step = settings.get_temperature_step()
            temperature_points = [0.0, 300.0] # For spectra
            temperatures = np.arange(t_min, t_max + float(t_step) / 10, t_step)
    else:
        temperature_points = settings.get_temperatures() # For spectra
        temperatures = settings.get_temperatures() # For others

    if settings.get_frequency_conversion_factor() is None:
        frequency_factor_to_THz = VaspToTHz
    else:
        frequency_factor_to_THz = settings.get_frequency_conversion_factor()

    if settings.get_num_frequency_points() is None:
        if settings.get_frequency_pitch() is None:
            num_frequency_points = 201
            frequency_step = None
        else:
            num_frequency_points = None
            frequency_step = settings.get_frequency_pitch()
    else:
        num_frequency_points = settings.get_num_frequency_points()
        frequency_step = None

    if settings.get_frequency_scale_factor() is None:
        frequency_scale_factor = None
    else:
        frequency_scale_factor = settings.get_frequency_scale_factor()

    if settings.get_cutoff_frequency() is None:
        cutoff_frequency = 1e-2
    else:
        cutoff_frequency = settings.get_cutoff_frequency()

    conf = {}
    conf['primitive_matrix'] = primitive_matrix
    conf['supercell_matrix'] = supercell_matrix
    conf['phonon_supercell_matrix'] = phonon_supercell_matrix
    conf['masses'] = masses
    conf['mesh'] = mesh
    conf['mesh_divs'] = mesh_divs
    conf['coarse_mesh_shifts'] = coarse_mesh_shifts
    conf['grid_points'] = grid_points
    conf['band_indices'] = band_indices
    conf['sigmas'] = sigmas
    conf['sigma_cutoff'] = sigma_cutoff
    conf['temperature_points'] = temperature_points
    conf['temperatures'] = temperatures
    conf['frequency_factor_to_THz'] = frequency_factor_to_THz
    conf['num_frequency_points'] = num_frequency_points
    conf['frequency_step'] = frequency_step
    conf['frequency_scale_factor'] = frequency_scale_factor
    conf['cutoff_frequency'] = cutoff_frequency

    return conf

@@ -1578,3599 +1578,4 @@
 GE.%0A
-%0Aimport numpy as np%0Afrom phonopy.units import VaspToTHz%0Afrom phono3py.phonon3.triplets import get_grid_point_from_address%0A%0A%0Adef get_phono3py_configurations(settings):%0A    primitive_matrix = settings.get_primitive_matrix()%0A    supercell_matrix = settings.get_supercell_matrix()%0A    phonon_supercell_matrix = settings.get_phonon_supercell_matrix()%0A    masses = settings.get_masses()%0A    mesh = settings.get_mesh_numbers()%0A    mesh_divs = settings.get_mesh_divisors()%0A    coarse_mesh_shifts = settings.get_coarse_mesh_shifts()%0A    grid_points = settings.get_grid_points()%0A    grid_addresses = settings.get_grid_addresses()%0A    if grid_addresses is not None:%0A        grid_points = %5Bget_grid_point_from_address(ga, mesh)%0A                       for ga in grid_addresses%5D%0A    band_indices = settings.get_band_indices()%0A%0A    # Brillouin zone integration: Tetrahedron (default) or smearing method%0A    sigma = settings.get_sigma()%0A    if sigma is None:%0A        sigmas = %5B%5D%0A    elif isinstance(sigma, float):%0A        sigmas = %5Bsigma%5D%0A    else:%0A        sigmas = sigma%0A    if settings.get_is_tetrahedron_method():%0A        sigmas = %5BNone%5D + sigmas%0A    if len(sigmas) == 0:%0A        sigmas = %5BNone%5D%0A%0A    sigma_cutoff = settings.get_sigma_cutoff_width()%0A%0A    if settings.get_temperatures() is None:%0A        if settings.get_is_joint_dos():%0A            temperature_points = None%0A            temperatures = None%0A        else:%0A            t_max = settings.get_max_temperature()%0A            t_min = settings.get_min_temperature()%0A            t_step = settings.get_temperature_step()%0A            temperature_points = %5B0.0, 300.0%5D # For spectra%0A            temperatures = np.arange(t_min, t_max + float(t_step) / 10, t_step)%0A    else:%0A        temperature_points = settings.get_temperatures() # For spectra%0A        temperatures = settings.get_temperatures() # For others%0A%0A    if settings.get_frequency_conversion_factor() is None:%0A        frequency_factor_to_THz = VaspToTHz%0A    else:%0A        frequency_factor_to_THz = settings.get_frequency_conversion_factor()%0A%0A    if settings.get_num_frequency_points() is None:%0A        if settings.get_frequency_pitch() is None:%0A            num_frequency_points = 201%0A            frequency_step = None%0A        else:%0A            num_frequency_points = None%0A            frequency_step = settings.get_frequency_pitch()%0A    else:%0A        num_frequency_points = settings.get_num_frequency_points()%0A        frequency_step = None%0A%0A    if settings.get_frequency_scale_factor() is None:%0A        frequency_scale_factor = None%0A    else:%0A        frequency_scale_factor = settings.get_frequency_scale_factor()%0A%0A    if settings.get_cutoff_frequency() is None:%0A        cutoff_frequency = 1e-2%0A    else:%0A        cutoff_frequency = settings.get_cutoff_frequency()%0A%0A    conf = %7B%7D%0A    conf%5B'primitive_matrix'%5D = primitive_matrix%0A    conf%5B'supercell_matrix'%5D = supercell_matrix%0A    conf%5B'phonon_supercell_matrix'%5D = phonon_supercell_matrix%0A    conf%5B'masses'%5D = masses%0A    conf%5B'mesh'%5D = mesh%0A    conf%5B'mesh_divs'%5D = mesh_divs%0A    conf%5B'coarse_mesh_shifts'%5D = coarse_mesh_shifts%0A    conf%5B'grid_points'%5D = grid_points%0A    conf%5B'band_indices'%5D = band_indices%0A    conf%5B'sigmas'%5D = sigmas%0A    conf%5B'sigma_cutoff'%5D = sigma_cutoff%0A    conf%5B'temperature_points'%5D = temperature_points%0A    conf%5B'temperatures'%5D = temperatures%0A    conf%5B'frequency_factor_to_THz'%5D = frequency_factor_to_THz%0A    conf%5B'num_frequency_points'%5D = num_frequency_points%0A    conf%5B'frequency_step'%5D = frequency_step%0A    conf%5B'frequency_scale_factor'%5D = frequency_scale_factor%0A    conf%5B'cutoff_frequency'%5D = cutoff_frequency%0A%0A    return conf%0A

Move the method in translate_settings.py to phono3py_script.py