Made phonon solver independent module

This commit is contained in:
Atsushi Togo 2021-02-22 10:24:25 +09:00
parent 7864c746d9
commit f79c31a198
12 changed files with 596 additions and 350 deletions

View File

@ -24,34 +24,6 @@ set(phono3py_micro_version ${CMAKE_MATCH_3})
set(serial "${phono3py_major_version}.${phono3py_minor_version}.${phono3py_micro_version}")
set(soserial "1")
# Source code
include_directories("${PROJECT_SOURCE_DIR}/c")
set(SOURCES
${PROJECT_SOURCE_DIR}/c/collision_matrix.c
${PROJECT_SOURCE_DIR}/c/dynmat.c
${PROJECT_SOURCE_DIR}/c/fc3.c
${PROJECT_SOURCE_DIR}/c/imag_self_energy_with_g.c
${PROJECT_SOURCE_DIR}/c/interaction.c
${PROJECT_SOURCE_DIR}/c/isotope.c
${PROJECT_SOURCE_DIR}/c/kgrid.c
${PROJECT_SOURCE_DIR}/c/kpoint.c
${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/mathfunc.c
${PROJECT_SOURCE_DIR}/c/phono3py.c
${PROJECT_SOURCE_DIR}/c/phonoc_utils.c
${PROJECT_SOURCE_DIR}/c/phonon.c
${PROJECT_SOURCE_DIR}/c/pp_collision.c
${PROJECT_SOURCE_DIR}/c/real_self_energy.c
${PROJECT_SOURCE_DIR}/c/real_to_reciprocal.c
${PROJECT_SOURCE_DIR}/c/reciprocal_to_normal.c
${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c
${PROJECT_SOURCE_DIR}/c/triplet.c
${PROJECT_SOURCE_DIR}/c/triplet_iw.c
${PROJECT_SOURCE_DIR}/c/triplet_kpoint.c)
# Shared library
add_library(ph3py SHARED ${SOURCES})
find_package(OpenMP)
if (OPENMP_FOUND)
set(openmp "-lgomp")
@ -64,6 +36,36 @@ link_directories($ENV{CONDA_PREFIX}/lib)
set(LAPACK_LIBRARIES "-llapack")
set(BLAS_LIBRARIES "-lopenblas")
############
# phono3py #
############
# Source code
include_directories("${PROJECT_SOURCE_DIR}/c")
set(SOURCES_PHONO3PY
${PROJECT_SOURCE_DIR}/c/collision_matrix.c
${PROJECT_SOURCE_DIR}/c/fc3.c
${PROJECT_SOURCE_DIR}/c/imag_self_energy_with_g.c
${PROJECT_SOURCE_DIR}/c/interaction.c
${PROJECT_SOURCE_DIR}/c/isotope.c
${PROJECT_SOURCE_DIR}/c/kgrid.c
${PROJECT_SOURCE_DIR}/c/kpoint.c
${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/mathfunc.c
${PROJECT_SOURCE_DIR}/c/phono3py.c
${PROJECT_SOURCE_DIR}/c/phonoc_utils.c
${PROJECT_SOURCE_DIR}/c/pp_collision.c
${PROJECT_SOURCE_DIR}/c/real_self_energy.c
${PROJECT_SOURCE_DIR}/c/real_to_reciprocal.c
${PROJECT_SOURCE_DIR}/c/reciprocal_to_normal.c
${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c
${PROJECT_SOURCE_DIR}/c/triplet.c
${PROJECT_SOURCE_DIR}/c/triplet_iw.c
${PROJECT_SOURCE_DIR}/c/triplet_kpoint.c)
# Shared library
add_library(ph3py SHARED ${SOURCES_PHONO3PY})
if(NOT MSVC)
target_link_libraries(ph3py m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${openmp})
endif()
@ -72,7 +74,7 @@ set_property(TARGET ph3py PROPERTY SOVERSION ${soserial})
install(TARGETS ph3py LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Static link library
add_library(ph3py_static STATIC ${SOURCES})
add_library(ph3py_static STATIC ${SOURCES_PHONO3PY})
set_property(TARGET ph3py_static PROPERTY VERSION ${serial})
set_property(TARGET ph3py_static PROPERTY SOVERSION ${soserial})
set_property(TARGET ph3py_static PROPERTY OUTPUT_NAME ph3py)
@ -80,3 +82,34 @@ install(TARGETS ph3py_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/phono3py.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
#############
# phononmod #
#############
# Source code
set(SOURCES_PHONONMOD
${PROJECT_SOURCE_DIR}/c/dynmat.c
${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/phonon.c
${PROJECT_SOURCE_DIR}/c/phononmod.c)
# Shared library
add_library(phmod SHARED ${SOURCES_PHONONMOD})
if(NOT MSVC)
target_link_libraries(phmod m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${openmp})
endif()
set_property(TARGET phmod PROPERTY VERSION ${serial})
set_property(TARGET phmod PROPERTY SOVERSION ${soserial})
install(TARGETS phmod LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Static link library
add_library(phmod_static STATIC ${SOURCES_PHONONMOD})
set_property(TARGET phmod_static PROPERTY VERSION ${serial})
set_property(TARGET phmod_static PROPERTY SOVERSION ${soserial})
set_property(TARGET phmod_static PROPERTY OUTPUT_NAME phmod)
install(TARGETS phmod_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/phononmod.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

View File

@ -44,7 +44,6 @@
#include "phonoc_array.h"
static PyObject * py_get_phonons_at_gridpoints(PyObject *self, PyObject *args);
static PyObject * py_get_interaction(PyObject *self, PyObject *args);
static PyObject * py_get_pp_collision(PyObject *self, PyObject *args);
static PyObject *
@ -121,10 +120,6 @@ error_out(PyObject *m) {
static PyMethodDef _phono3py_methods[] = {
{"error_out", (PyCFunction)error_out, METH_NOARGS, NULL},
{"phonons_at_gridpoints",
py_get_phonons_at_gridpoints,
METH_VARARGS,
"Set phonons at grid points"},
{"interaction",
(PyCFunction)py_get_interaction,
METH_VARARGS,
@ -294,167 +289,6 @@ PyInit__phono3py(void)
#endif
}
static PyObject * py_get_phonons_at_gridpoints(PyObject *self, PyObject *args)
{
PyArrayObject* py_frequencies;
PyArrayObject* py_eigenvectors;
PyArrayObject* py_phonon_done;
PyArrayObject* py_grid_points;
PyArrayObject* py_grid_address;
PyArrayObject* py_mesh;
PyArrayObject* py_shortest_vectors_fc2;
PyArrayObject* py_multiplicity_fc2;
PyArrayObject* py_positions_fc2;
PyArrayObject* py_fc2;
PyArrayObject* py_masses_fc2;
PyArrayObject* py_p2s_map_fc2;
PyArrayObject* py_s2p_map_fc2;
PyArrayObject* py_reciprocal_lattice;
PyArrayObject* py_born_effective_charge;
PyArrayObject* py_q_direction;
PyArrayObject* py_dielectric_constant;
PyArrayObject* py_dd_q0;
PyArrayObject* py_G_list;
double nac_factor;
double unit_conversion_factor;
double lambda;
char* uplo;
double (*born)[3][3];
double (*dielectric)[3];
double *q_dir;
double* freqs;
lapack_complex_double* eigvecs;
char* phonon_done;
long* grid_points;
long (*grid_address)[3];
long* mesh;
double* fc2;
double(*svecs_fc2)[27][3];
long* multi_fc2;
double (*positions_fc2)[3];
double* masses_fc2;
long* p2s_fc2;
long* s2p_fc2;
double (*rec_lat)[3];
double * dd_q0;
double (*G_list)[3];
long num_patom, num_satom, num_phonons, num_grid_points, num_G_points;
if (!PyArg_ParseTuple(args, "OOOOOOOOOOOOOdOOOOdOOds",
&py_frequencies,
&py_eigenvectors,
&py_phonon_done,
&py_grid_points,
&py_grid_address,
&py_mesh,
&py_fc2,
&py_shortest_vectors_fc2,
&py_multiplicity_fc2,
&py_positions_fc2,
&py_masses_fc2,
&py_p2s_map_fc2,
&py_s2p_map_fc2,
&unit_conversion_factor,
&py_born_effective_charge,
&py_dielectric_constant,
&py_reciprocal_lattice,
&py_q_direction,
&nac_factor,
&py_dd_q0,
&py_G_list,
&lambda,
&uplo)) {
return NULL;
}
freqs = (double*)PyArray_DATA(py_frequencies);
eigvecs = (lapack_complex_double*)PyArray_DATA(py_eigenvectors);
phonon_done = (char*)PyArray_DATA(py_phonon_done);
grid_points = (long*)PyArray_DATA(py_grid_points);
grid_address = (long(*)[3])PyArray_DATA(py_grid_address);
mesh = (long*)PyArray_DATA(py_mesh);
fc2 = (double*)PyArray_DATA(py_fc2);
svecs_fc2 = (double(*)[27][3])PyArray_DATA(py_shortest_vectors_fc2);
multi_fc2 = (long*)PyArray_DATA(py_multiplicity_fc2);
masses_fc2 = (double*)PyArray_DATA(py_masses_fc2);
p2s_fc2 = (long*)PyArray_DATA(py_p2s_map_fc2);
s2p_fc2 = (long*)PyArray_DATA(py_s2p_map_fc2);
rec_lat = (double(*)[3])PyArray_DATA(py_reciprocal_lattice);
num_patom = (long)PyArray_DIMS(py_multiplicity_fc2)[1];
num_satom = (long)PyArray_DIMS(py_multiplicity_fc2)[0];
num_phonons = (long)PyArray_DIMS(py_frequencies)[0];
num_grid_points = (long)PyArray_DIMS(py_grid_points)[0];
if ((PyObject*)py_born_effective_charge == Py_None) {
born = NULL;
} else {
born = (double(*)[3][3])PyArray_DATA(py_born_effective_charge);
}
if ((PyObject*)py_dielectric_constant == Py_None) {
dielectric = NULL;
} else {
dielectric = (double(*)[3])PyArray_DATA(py_dielectric_constant);
}
if ((PyObject*)py_q_direction == Py_None) {
q_dir = NULL;
} else {
q_dir = (double*)PyArray_DATA(py_q_direction);
if (fabs(q_dir[0]) < 1e-10 &&
fabs(q_dir[1]) < 1e-10 &&
fabs(q_dir[2]) < 1e-10) {
q_dir = NULL;
}
}
if ((PyObject*)py_dd_q0 == Py_None) {
dd_q0 = NULL;
} else {
dd_q0 = (double*)PyArray_DATA(py_dd_q0);
}
if ((PyObject*)py_G_list == Py_None) {
G_list = NULL;
num_G_points = 0;
} else {
G_list = (double(*)[3])PyArray_DATA(py_G_list);
num_G_points = (long)PyArray_DIMS(py_G_list)[0];
}
if ((PyObject*)py_positions_fc2 == Py_None) {
positions_fc2 = NULL;
} else {
positions_fc2 = (double(*)[3])PyArray_DATA(py_positions_fc2);
}
ph3py_get_phonons_at_gridpoints(freqs,
eigvecs,
phonon_done,
num_phonons,
grid_points,
num_grid_points,
grid_address,
mesh,
fc2,
svecs_fc2,
multi_fc2,
positions_fc2,
num_patom,
num_satom,
masses_fc2,
p2s_fc2,
s2p_fc2,
unit_conversion_factor,
born,
dielectric,
rec_lat,
q_dir,
nac_factor,
dd_q0,
G_list,
num_G_points,
lambda,
uplo[0]);
Py_RETURN_NONE;
}
static PyObject * py_get_interaction(PyObject *self, PyObject *args)
{
PyArrayObject *py_fc3_normal_squared;

287
c/_phononmod.c Normal file
View File

@ -0,0 +1,287 @@
/* Copyright (C) 2021 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. */
#include <Python.h>
#include <numpy/arrayobject.h>
#include "lapack_wrapper.h"
#include "phononmod.h"
static PyObject * py_get_phonons_at_gridpoints(PyObject *self, PyObject *args);
struct module_state {
PyObject *error;
};
#if PY_MAJOR_VERSION >= 3
#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
#else
#define GETSTATE(m) (&_state)
static struct module_state _state;
#endif
static PyObject *
error_out(PyObject *m) {
struct module_state *st = GETSTATE(m);
PyErr_SetString(st->error, "something bad happened");
return NULL;
}
static PyMethodDef _phononmod_methods[] = {
{"error_out", (PyCFunction)error_out, METH_NOARGS, NULL},
{"phonons_at_gridpoints",
py_get_phonons_at_gridpoints,
METH_VARARGS,
"Set phonons at grid points"},
{NULL, NULL, 0, NULL}
};
#if PY_MAJOR_VERSION >= 3
static int _phononmod_traverse(PyObject *m, visitproc visit, void *arg) {
Py_VISIT(GETSTATE(m)->error);
return 0;
}
static int _phononmod_clear(PyObject *m) {
Py_CLEAR(GETSTATE(m)->error);
return 0;
}
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"_phononmod",
NULL,
sizeof(struct module_state),
_phononmod_methods,
NULL,
_phononmod_traverse,
_phononmod_clear,
NULL
};
#define INITERROR return NULL
PyObject *
PyInit__phononmod(void)
#else
#define INITERROR return
void
init_phononmod(void)
#endif
{
#if PY_MAJOR_VERSION >= 3
PyObject *module = PyModule_Create(&moduledef);
#else
PyObject *module = Py_InitModule("_phononmod", _phononmod_methods);
#endif
struct module_state *st;
if (module == NULL)
INITERROR;
st = GETSTATE(module);
st->error = PyErr_NewException("_phononmod.Error", NULL, NULL);
if (st->error == NULL) {
Py_DECREF(module);
INITERROR;
}
#if PY_MAJOR_VERSION >= 3
return module;
#endif
}
static PyObject * py_get_phonons_at_gridpoints(PyObject *self, PyObject *args)
{
PyArrayObject* py_frequencies;
PyArrayObject* py_eigenvectors;
PyArrayObject* py_phonon_done;
PyArrayObject* py_grid_points;
PyArrayObject* py_grid_address;
PyArrayObject* py_mesh;
PyArrayObject* py_shortest_vectors_fc2;
PyArrayObject* py_multiplicity_fc2;
PyArrayObject* py_positions_fc2;
PyArrayObject* py_fc2;
PyArrayObject* py_masses_fc2;
PyArrayObject* py_p2s_map_fc2;
PyArrayObject* py_s2p_map_fc2;
PyArrayObject* py_reciprocal_lattice;
PyArrayObject* py_born_effective_charge;
PyArrayObject* py_q_direction;
PyArrayObject* py_dielectric_constant;
PyArrayObject* py_dd_q0;
PyArrayObject* py_G_list;
double nac_factor;
double unit_conversion_factor;
double lambda;
char* uplo;
double (*born)[3][3];
double (*dielectric)[3];
double *q_dir;
double* freqs;
lapack_complex_double* eigvecs;
char* phonon_done;
long* grid_points;
long (*grid_address)[3];
long* mesh;
double* fc2;
double(*svecs_fc2)[27][3];
long* multi_fc2;
double (*positions_fc2)[3];
double* masses_fc2;
long* p2s_fc2;
long* s2p_fc2;
double (*rec_lat)[3];
double * dd_q0;
double (*G_list)[3];
long num_patom, num_satom, num_phonons, num_grid_points, num_G_points;
if (!PyArg_ParseTuple(args, "OOOOOOOOOOOOOdOOOOdOOds",
&py_frequencies,
&py_eigenvectors,
&py_phonon_done,
&py_grid_points,
&py_grid_address,
&py_mesh,
&py_fc2,
&py_shortest_vectors_fc2,
&py_multiplicity_fc2,
&py_positions_fc2,
&py_masses_fc2,
&py_p2s_map_fc2,
&py_s2p_map_fc2,
&unit_conversion_factor,
&py_born_effective_charge,
&py_dielectric_constant,
&py_reciprocal_lattice,
&py_q_direction,
&nac_factor,
&py_dd_q0,
&py_G_list,
&lambda,
&uplo)) {
return NULL;
}
freqs = (double*)PyArray_DATA(py_frequencies);
eigvecs = (lapack_complex_double*)PyArray_DATA(py_eigenvectors);
phonon_done = (char*)PyArray_DATA(py_phonon_done);
grid_points = (long*)PyArray_DATA(py_grid_points);
grid_address = (long(*)[3])PyArray_DATA(py_grid_address);
mesh = (long*)PyArray_DATA(py_mesh);
fc2 = (double*)PyArray_DATA(py_fc2);
svecs_fc2 = (double(*)[27][3])PyArray_DATA(py_shortest_vectors_fc2);
multi_fc2 = (long*)PyArray_DATA(py_multiplicity_fc2);
masses_fc2 = (double*)PyArray_DATA(py_masses_fc2);
p2s_fc2 = (long*)PyArray_DATA(py_p2s_map_fc2);
s2p_fc2 = (long*)PyArray_DATA(py_s2p_map_fc2);
rec_lat = (double(*)[3])PyArray_DATA(py_reciprocal_lattice);
num_patom = (long)PyArray_DIMS(py_multiplicity_fc2)[1];
num_satom = (long)PyArray_DIMS(py_multiplicity_fc2)[0];
num_phonons = (long)PyArray_DIMS(py_frequencies)[0];
num_grid_points = (long)PyArray_DIMS(py_grid_points)[0];
if ((PyObject*)py_born_effective_charge == Py_None) {
born = NULL;
} else {
born = (double(*)[3][3])PyArray_DATA(py_born_effective_charge);
}
if ((PyObject*)py_dielectric_constant == Py_None) {
dielectric = NULL;
} else {
dielectric = (double(*)[3])PyArray_DATA(py_dielectric_constant);
}
if ((PyObject*)py_q_direction == Py_None) {
q_dir = NULL;
} else {
q_dir = (double*)PyArray_DATA(py_q_direction);
if (fabs(q_dir[0]) < 1e-10 &&
fabs(q_dir[1]) < 1e-10 &&
fabs(q_dir[2]) < 1e-10) {
q_dir = NULL;
}
}
if ((PyObject*)py_dd_q0 == Py_None) {
dd_q0 = NULL;
} else {
dd_q0 = (double*)PyArray_DATA(py_dd_q0);
}
if ((PyObject*)py_G_list == Py_None) {
G_list = NULL;
num_G_points = 0;
} else {
G_list = (double(*)[3])PyArray_DATA(py_G_list);
num_G_points = (long)PyArray_DIMS(py_G_list)[0];
}
if ((PyObject*)py_positions_fc2 == Py_None) {
positions_fc2 = NULL;
} else {
positions_fc2 = (double(*)[3])PyArray_DATA(py_positions_fc2);
}
phmod_get_phonons_at_gridpoints(freqs,
eigvecs,
phonon_done,
num_phonons,
grid_points,
num_grid_points,
grid_address,
mesh,
fc2,
svecs_fc2,
multi_fc2,
positions_fc2,
num_patom,
num_satom,
masses_fc2,
p2s_fc2,
s2p_fc2,
unit_conversion_factor,
born,
dielectric,
rec_lat,
q_dir,
nac_factor,
dd_q0,
G_list,
num_G_points,
lambda,
uplo[0]);
Py_RETURN_NONE;
}

View File

@ -35,7 +35,9 @@
#ifndef __dynmat_H__
#define __dynmat_H__
#ifndef PHPYCONST
#define PHPYCONST
#endif
long dym_get_dynamical_matrix_at_q(double *dynamical_matrix,
const long num_patom,

View File

@ -36,7 +36,6 @@
#include "lapack_wrapper.h"
#include "phonoc_array.h"
#include "phonon.h"
#include "interaction.h"
#include "pp_collision.h"
#include "imag_self_energy_with_g.h"
@ -49,92 +48,6 @@
#include <stdio.h>
void ph3py_get_phonons_at_gridpoints(double *frequencies,
lapack_complex_double *eigenvectors,
char *phonon_done,
const long num_phonons,
const long *grid_points,
const long num_grid_points,
PHPYCONST long (*grid_address)[3],
const long mesh[3],
const double *fc2,
PHPYCONST double(*svecs_fc2)[27][3],
const long *multi_fc2,
PHPYCONST double (*positions_fc2)[3],
const long num_patom,
const long num_satom,
const double *masses_fc2,
const long *p2s_fc2,
const long *s2p_fc2,
const double unit_conversion_factor,
PHPYCONST double (*born)[3][3],
PHPYCONST double dielectric[3][3],
PHPYCONST double reciprocal_lattice[3][3],
const double *q_direction, /* pointer */
const double nac_factor,
const double *dd_q0,
PHPYCONST double(*G_list)[3],
const long num_G_points,
const double lambda,
const char uplo)
{
if (!dd_q0) {
phn_get_phonons_at_gridpoints(frequencies,
eigenvectors,
phonon_done,
num_phonons,
grid_points,
num_grid_points,
grid_address,
mesh,
fc2,
svecs_fc2,
multi_fc2,
num_patom,
num_satom,
masses_fc2,
p2s_fc2,
s2p_fc2,
unit_conversion_factor,
born,
dielectric,
reciprocal_lattice,
q_direction,
nac_factor,
uplo);
} else {
phn_get_gonze_phonons_at_gridpoints(frequencies,
eigenvectors,
phonon_done,
num_phonons,
grid_points,
num_grid_points,
grid_address,
mesh,
fc2,
svecs_fc2,
multi_fc2,
positions_fc2,
num_patom,
num_satom,
masses_fc2,
p2s_fc2,
s2p_fc2,
unit_conversion_factor,
born,
dielectric,
reciprocal_lattice,
q_direction,
nac_factor,
dd_q0,
G_list,
num_G_points,
lambda,
uplo);
}
}
void ph3py_get_interaction(Darray *fc3_normal_squared,
const char *g_zero,
const Darray *frequencies,

View File

@ -42,34 +42,6 @@
#include "lapack_wrapper.h"
#include "phonoc_array.h"
void ph3py_get_phonons_at_gridpoints(double *frequencies,
lapack_complex_double *eigenvectors,
char *phonon_done,
const long num_phonons,
const long *grid_points,
const long num_grid_points,
PHPYCONST long (*grid_address)[3],
const long mesh[3],
const double *fc2,
PHPYCONST double(*svecs_fc2)[27][3],
const long *multi_fc2,
PHPYCONST double (*positions_fc2)[3],
const long num_patom,
const long num_satom,
const double *masses_fc2,
const long *p2s_fc2,
const long *s2p_fc2,
const double unit_conversion_factor,
PHPYCONST double (*born)[3][3],
PHPYCONST double dielectric[3][3],
PHPYCONST double reciprocal_lattice[3][3],
const double *q_direction, /* pointer */
const double nac_factor,
const double *dd_q0,
PHPYCONST double(*G_list)[3],
const long num_G_points,
const double lambda,
const char uplo);
void ph3py_get_interaction(Darray *fc3_normal_squared,
const char *g_zero,
const Darray *frequencies,

View File

@ -33,8 +33,6 @@
/* POSSIBILITY OF SUCH DAMAGE. */
#include <math.h>
#include "dynmat.h"
#include "phonoc_array.h"
#include "phonoc_const.h"
#include "phonoc_utils.h"
#include "lapack_wrapper.h"

View File

@ -35,7 +35,6 @@
#ifndef __phonoc_utils_H__
#define __phonoc_utils_H__
#include "phonoc_array.h"
#include "lapack_wrapper.h"
double bose_einstein(const double x, const double t);

122
c/phononmod.c Normal file
View File

@ -0,0 +1,122 @@
/* Copyright (C) 2021 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. */
#include "phononmod.h"
#include "lapack_wrapper.h"
#include "phonon.h"
void phmod_get_phonons_at_gridpoints(double *frequencies,
lapack_complex_double *eigenvectors,
char *phonon_done,
const long num_phonons,
const long *grid_points,
const long num_grid_points,
PHPYCONST long (*grid_address)[3],
const long mesh[3],
const double *fc2,
PHPYCONST double(*svecs_fc2)[27][3],
const long *multi_fc2,
PHPYCONST double (*positions_fc2)[3],
const long num_patom,
const long num_satom,
const double *masses_fc2,
const long *p2s_fc2,
const long *s2p_fc2,
const double unit_conversion_factor,
PHPYCONST double (*born)[3][3],
PHPYCONST double dielectric[3][3],
PHPYCONST double reciprocal_lattice[3][3],
const double *q_direction, /* pointer */
const double nac_factor,
const double *dd_q0,
PHPYCONST double(*G_list)[3],
const long num_G_points,
const double lambda,
const char uplo)
{
if (!dd_q0) {
phn_get_phonons_at_gridpoints(frequencies,
eigenvectors,
phonon_done,
num_phonons,
grid_points,
num_grid_points,
grid_address,
mesh,
fc2,
svecs_fc2,
multi_fc2,
num_patom,
num_satom,
masses_fc2,
p2s_fc2,
s2p_fc2,
unit_conversion_factor,
born,
dielectric,
reciprocal_lattice,
q_direction,
nac_factor,
uplo);
} else {
phn_get_gonze_phonons_at_gridpoints(frequencies,
eigenvectors,
phonon_done,
num_phonons,
grid_points,
num_grid_points,
grid_address,
mesh,
fc2,
svecs_fc2,
multi_fc2,
positions_fc2,
num_patom,
num_satom,
masses_fc2,
p2s_fc2,
s2p_fc2,
unit_conversion_factor,
born,
dielectric,
reciprocal_lattice,
q_direction,
nac_factor,
dd_q0,
G_list,
num_G_points,
lambda,
uplo);
}
}

73
c/phononmod.h Normal file
View File

@ -0,0 +1,73 @@
/* Copyright (C) 2021 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. */
#ifndef __phononmod_H__
#define __phononmod_H__
#ifndef PHPYCONST
#define PHPYCONST
#endif
#include "lapack_wrapper.h"
void phmod_get_phonons_at_gridpoints(double *frequencies,
lapack_complex_double *eigenvectors,
char *phonon_done,
const long num_phonons,
const long *grid_points,
const long num_grid_points,
PHPYCONST long (*grid_address)[3],
const long mesh[3],
const double *fc2,
PHPYCONST double(*svecs_fc2)[27][3],
const long *multi_fc2,
PHPYCONST double (*positions_fc2)[3],
const long num_patom,
const long num_satom,
const double *masses_fc2,
const long *p2s_fc2,
const long *s2p_fc2,
const double unit_conversion_factor,
PHPYCONST double (*born)[3][3],
PHPYCONST double dielectric[3][3],
PHPYCONST double reciprocal_lattice[3][3],
const double *q_direction, /* pointer */
const double nac_factor,
const double *dd_q0,
PHPYCONST double(*G_list)[3],
const long num_G_points,
const double lambda,
const char uplo);
#endif

View File

@ -46,7 +46,7 @@ def run_phonon_solver_c(dm,
nac_q_direction, # in reduced coordinates
lapack_zheev_uplo,
verbose=False):
import phono3py._phono3py as phono3c
import phono3py._phononmod as phononmod
(svecs,
multiplicity,
@ -79,7 +79,7 @@ def run_phonon_solver_c(dm,
# assert grid_points.flags.c_contiguous
fc_p2s, fc_s2p = _get_fc_elements_mapping(dm, fc)
phono3c.phonons_at_gridpoints(
phononmod.phonons_at_gridpoints(
frequencies,
eigenvectors,
phonon_done,

View File

@ -34,29 +34,6 @@ if (config_var is not None and
os.environ['CFLAGS'] = config_var.replace(
"-Werror=declaration-after-statement", "")
sources = ['c/_phono3py.c',
'c/collision_matrix.c',
'c/dynmat.c',
'c/fc3.c',
'c/imag_self_energy_with_g.c',
'c/interaction.c',
'c/isotope.c',
'c/kgrid.c',
'c/kpoint.c',
'c/lapack_wrapper.c',
'c/mathfunc.c',
'c/phono3py.c',
'c/phonoc_utils.c',
'c/phonon.c',
'c/pp_collision.c',
'c/real_self_energy.c',
'c/real_to_reciprocal.c',
'c/reciprocal_to_normal.c',
'c/tetrahedron_method.c',
'c/triplet.c',
'c/triplet_iw.c',
'c/triplet_kpoint.c']
extra_compile_args = ['-fopenmp', ]
include_dirs = ['c', ] + include_dirs_numpy
define_macros = []
@ -229,13 +206,54 @@ extra_link_args += extra_link_args_lapacke
include_dirs += include_dirs_lapacke
print("extra_link_args", extra_link_args)
sources_phono3py = ['c/_phono3py.c',
'c/collision_matrix.c',
'c/fc3.c',
'c/imag_self_energy_with_g.c',
'c/interaction.c',
'c/isotope.c',
'c/kgrid.c',
'c/kpoint.c',
'c/lapack_wrapper.c',
'c/mathfunc.c',
'c/phono3py.c',
'c/phonoc_utils.c',
'c/pp_collision.c',
'c/real_self_energy.c',
'c/real_to_reciprocal.c',
'c/reciprocal_to_normal.c',
'c/tetrahedron_method.c',
'c/triplet.c',
'c/triplet_iw.c',
'c/triplet_kpoint.c']
extension_phono3py = Extension(
'phono3py._phono3py',
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
define_macros=define_macros,
sources=sources)
sources=sources_phono3py)
sources_phononmod = ['c/_phononmod.c',
'c/dynmat.c',
'c/lapack_wrapper.c',
'c/phonon.c',
'c/phononmod.c']
extension_phononmod = Extension(
'phono3py._phononmod',
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
sources=sources_phononmod)
sources_lapackepy = ['c/_lapackepy.c',
'c/lapack_wrapper.c']
extension_lapackepy = Extension(
'phono3py._lapackepy',
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
include_dirs=include_dirs,
sources=sources_lapackepy)
packages_phono3py = ['phono3py',
'phono3py.cui',
@ -253,15 +271,6 @@ scripts_phono3py = ['scripts/phono3py',
########################
# _lapackepy extension #
########################
include_dirs_lapackepy = (['c', ] + include_dirs_numpy + include_dirs_lapacke)
sources_lapackepy = ['c/_lapackepy.c',
'c/lapack_wrapper.c']
extension_lapackepy = Extension(
'phono3py._lapackepy',
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
include_dirs=include_dirs_lapackepy,
sources=sources_lapackepy)
if __name__ == '__main__':
version_nums = [None, None, None]
@ -308,7 +317,9 @@ if __name__ == '__main__':
'h5py', 'spglib', 'phonopy>=2.9,<2.10'],
provides=['phono3py'],
scripts=scripts_phono3py,
ext_modules=[extension_lapackepy, extension_phono3py])
ext_modules=[extension_phono3py,
extension_lapackepy,
extension_phononmod])
else:
setup(name='phono3py',
version=version,
@ -321,4 +332,6 @@ if __name__ == '__main__':
'phonopy', 'spglib'],
provides=['phono3py'],
scripts=scripts_phono3py,
ext_modules=[extension_lapackepy, extension_phono3py])
ext_modules=[extension_phono3py,
extension_lapackepy,
extension_phononmod])