├── .github └── workflows │ ├── build-and-test-ALM-conda.yml │ └── windows-conda.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .readthedocs.yaml ├── CMakeLists.txt ├── CMakeLists.txt.conda ├── LICENSE.txt ├── README.md ├── conda ├── build.sh └── meta.yaml ├── docs ├── .nojekyll ├── Makefile ├── alm.rst ├── compile-with-conda-packages.rst ├── compile-with-makefile.rst ├── conf.py ├── formalism.rst ├── format-dfset.rst ├── index.rst ├── input-tags.rst ├── intro.rst ├── modules.rst ├── python-module.rst └── requirements.txt ├── etc └── alm-environment.yml ├── example ├── AlN │ ├── AlN-lasso.py │ ├── DFSET_AlN.lzma │ ├── POSCAR_AlN │ └── README ├── Si_fitting.cpp ├── Si_fitting.py ├── Si_fitting2.cpp ├── Si_fitting2.py ├── Si_fitting_external.py ├── Si_fitting_insteps.py ├── Si_suggest.cpp ├── Si_suggest.py ├── Si_suggest2.cpp ├── Si_suggest2.py ├── disp.dat ├── force.dat ├── lasso │ ├── LASSO_example.ipynb │ ├── LASSO_example.py │ ├── disp_random.dat │ └── force_random.dat ├── show_fc_dependency.py ├── sparse_Eigen.py └── write_fcsxml.py ├── external └── combination.hpp ├── python ├── _alm.c ├── alm │ ├── __init__.py │ ├── alm.py │ └── fcsxml.py ├── alm_wrapper.cpp ├── alm_wrapper.h ├── pyproject.toml ├── setup.cfg └── setup.py ├── src ├── Makefile.linux ├── Makefile.osx ├── alm.cpp ├── alm.h ├── alm_cui.cpp ├── alm_cui.h ├── cluster.cpp ├── cluster.h ├── combination.h ├── constants.h ├── constraint.cpp ├── constraint.h ├── error.h ├── fcs.cpp ├── fcs.h ├── files.cpp ├── files.h ├── input_parser.cpp ├── input_parser.h ├── input_setter.cpp ├── input_setter.h ├── main.cpp ├── mathfunctions.h ├── memory.h ├── optimize.cpp ├── optimize.h ├── patterndisp.cpp ├── patterndisp.h ├── rref.cpp ├── rref.h ├── symmetry.cpp ├── symmetry.h ├── system.cpp ├── system.h ├── timer.cpp ├── timer.h ├── version.h ├── writer.cpp ├── writer.h └── xml_parser.h ├── test ├── SiC_fitting.py ├── Si_fitting.py ├── kd.dat ├── lavec.dat ├── si_disp.dat ├── si_force.dat ├── sic_disp.dat ├── sic_force.dat └── xcoord.dat └── tools ├── README.md ├── displace.py ├── extract.py └── interface ├── LAMMPS.py ├── OpenMX.py ├── QE.py ├── VASP.py ├── __init__.py └── xTAPP.py /.github/workflows/build-and-test-ALM-conda.yml: -------------------------------------------------------------------------------- 1 | name: Conda build 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | paths: 7 | - '**.cpp' 8 | - '**.h' 9 | - '**.py' 10 | - '**.c' 11 | 12 | jobs: 13 | build: 14 | runs-on: ${{ matrix.os }} 15 | strategy: 16 | matrix: 17 | os: [ubuntu-latest, macOS-latest] 18 | # os: [ubuntu-latest, windows-latest, macOS-latest] 19 | python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] 20 | name: OS ${{ matrix.os }} Python ${{ matrix.python-version }} 21 | defaults: 22 | run: 23 | shell: bash -l {0} 24 | steps: 25 | - uses: actions/checkout@v3 26 | - name: Setup Mambaforge 27 | uses: conda-incubator/setup-miniconda@v2 28 | with: 29 | miniforge-variant: Mambaforge 30 | miniforge-version: latest 31 | activate-environment: alm 32 | use-mamba: true 33 | python-version: ${{ matrix.python-version }} 34 | 35 | 36 | - name: Get Date 37 | id: get-date 38 | run: echo "::set-output name=today::$(/bin/date -u '+%Y%m%d')" 39 | shell: bash 40 | 41 | - name: Cache Conda env 42 | uses: actions/cache@v2 43 | env: 44 | # Increase this value to reset cache if etc/alm-environment.yml has not changed 45 | CACHE_NUMBER: 0 46 | with: 47 | path: ${{ env.CONDA }}/envs 48 | key: conda-${{ runner.os }}--${{ runner.arch }}--${{ steps.get-date.outputs.today }}-${{ hashFiles('etc/alm-environment.yml') }}-${{ env.CACHE_NUMBER }} 49 | id: cache 50 | 51 | - name: Update environment 52 | run: mamba env update -n anaconda-client-env -f etc/alm-environment.yml 53 | if: steps.cache.outputs.cache-hit != 'true' 54 | - run: | 55 | conda info 56 | conda list 57 | conda config --show-sources 58 | conda config --show 59 | printenv | sort 60 | - name: Install conda libraries 61 | run: mamba install numpy scipy h5py compilers spglib boost eigen cmake 62 | 63 | - run: echo ${CC} ${CXX} 64 | 65 | - name: Build ALM library 66 | working-directory: ./python 67 | run: python -m pip install . 68 | - name: Run test Si 69 | working-directory: ./test 70 | run: python Si_fitting.py 71 | - name: Run test SiC 72 | working-directory: ./test 73 | run: python SiC_fitting.py 74 | 75 | -------------------------------------------------------------------------------- /.github/workflows/windows-conda.yml: -------------------------------------------------------------------------------- 1 | name: Python Package using Conda 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build: 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | os: [windows-latest] 12 | python-version: [3.8] 13 | name: OS ${{ matrix.os }} Python ${{ matrix.python-version }} 14 | defaults: 15 | run: 16 | shell: bash -l {0} 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Setup conda 20 | uses: conda-incubator/setup-miniconda@v2 21 | with: 22 | activate-environment: alm 23 | python-version: ${{ matrix.python-version }} 24 | auto-update-conda: false 25 | channels: conda-forge 26 | - run: | 27 | conda info 28 | conda list 29 | conda config --show-sources 30 | conda config --show 31 | - name: Install conda libraries 32 | run: conda install --yes numpy scipy h5py m2w64-gcc spglib boost eigen cmake 33 | - run: export 34 | - run: echo ${CC} ${CXX} 35 | - run: which g++; which gcc 36 | - run: export CC=gcc; export CXX=g++ 37 | - run: echo ${CC} ${CXX} 38 | - name: Build ALM library 39 | working-directory: ./python 40 | run: CC=gcc CXX=g++ python setup.py build 41 | - name: Place ALM library 42 | working-directory: ./python 43 | run: pip install -e . 44 | - name: Run test Si 45 | working-directory: ./test 46 | run: python Si_fitting.py 47 | - name: Run test SiC 48 | working-directory: ./test 49 | run: python SiC_fitting.py 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *~ 3 | _build 4 | build 5 | python/dist 6 | python/alm.egg-info 7 | TAGS 8 | include 9 | lib 10 | src/alm 11 | a.out 12 | *.obj 13 | Release/ 14 | Debug/ 15 | .vs/ 16 | *.db 17 | *.opendb 18 | alm.VC.VC.opendb 19 | src/alm.vcxproj.user 20 | *.filters 21 | /src/alm.vcxproj.user 22 | *.TMP 23 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # See https://pre-commit.com for more informatio 2 | # See https://pre-commit.com/hooks.html for more hooks 3 | repos: 4 | - repo: https://github.com/pre-commit/pre-commit-hooks 5 | rev: v4.2.0 6 | hooks: 7 | - id: trailing-whitespace 8 | files: ^python/ 9 | - id: end-of-file-fixer 10 | files: ^python/ 11 | - id: check-yaml 12 | files: python/ 13 | - id: check-added-large-files 14 | files: ^python/ 15 | 16 | - repo: https://github.com/pycqa/flake8 17 | rev: 4.0.1 18 | hooks: 19 | - id: flake8 20 | files: ^python/ 21 | args: 22 | - "--max-line-length=88" 23 | - "--ignore=E203,W503" 24 | 25 | - repo: https://github.com/psf/black 26 | rev: 22.3.0 27 | hooks: 28 | - id: black 29 | files: ^pytnon/ 30 | args: 31 | - --line-length=88 32 | 33 | - repo: https://github.com/pycqa/pydocstyle 34 | rev: 6.1.1 35 | hooks: 36 | - id: pydocstyle 37 | files: ^python/ 38 | 39 | - repo: https://github.com/pycqa/isort 40 | rev: 5.10.1 41 | hooks: 42 | - id: isort 43 | files: ^python/ 44 | name: isort (python) 45 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | build: 4 | os: ubuntu-22.04 5 | tools: 6 | python: "3.12" 7 | 8 | sphinx: 9 | configuration: docs/conf.py 10 | 11 | python: 12 | install: 13 | - requirements: docs/requirements.txt 14 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | set(CMAKE_CXX_STANDARD 11) 3 | set(CMAKE_CXX_STANDARD_REQUIRED True) 4 | set(CMAKE_MACOSX_RPATH 1) 5 | set(CMAKE_CXX_FLAGS_RELEASE "-O2") 6 | set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -O0 -D_DEBUG") 7 | #set(CMAKE_BUILD_TYPE DEBUG) 8 | set(CMAKE_BUILD_TYPE RELEASE) 9 | 10 | project(alm) 11 | 12 | if(WIN32) 13 | LINK_DIRECTORIES(C:\\lapack) 14 | LINK_DIRECTORIES(C:\\spglib) 15 | include_directories(C:\\spglib) 16 | set(LAPACK_LIBRARIES lapack) 17 | set(spglib symspg) 18 | endif() 19 | 20 | if (UNIX) 21 | find_package(LAPACK REQUIRED) 22 | include_directories(${Lapack_INCLUDE_DIRS}) 23 | endif() 24 | 25 | if (SPGLIB_ROOT) 26 | include_directories("${SPGLIB_ROOT}/include") 27 | set(spglib "-L${SPGLIB_ROOT}/lib -L${SPGLIB_ROOT}/lib64 -lsymspg") 28 | else() 29 | message("SPGLIB_ROOT is not given by -DSPGLIB_ROOT option. Just add -lsymspg.") 30 | set(spglib "-lsymspg") 31 | endif() 32 | 33 | # 34 | # Add openmp flag if available 35 | # 36 | find_package(OpenMP REQUIRED) 37 | if (OPENMP_FOUND) 38 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 39 | set (openmplibrary OpenMP::OpenMP_CXX) 40 | endif() 41 | 42 | find_package(Boost) 43 | if (Boost_FOUND) 44 | include_directories(${Boost_INCLUDE_DIRS}) 45 | else() 46 | if (BOOST_INCLUDE) 47 | include_directories(${BOOST_INCLUDE}) 48 | else() 49 | message(FATAL_ERROR "Boost was not found. 50 | Please specify the location of boost include directories 51 | via -DBOOST_INCLUDE option.") 52 | endif() 53 | endif() 54 | 55 | find_package(Eigen3) 56 | if (Eigen3_FOUND) 57 | include_directories(${EIGEN3_INCLUDE_DIR}) 58 | else() 59 | if (EIGEN3_INCLUDE) 60 | include_directories(${EIGEN3_INCLUDE}) 61 | else() 62 | message(FATAL_ERROR "Eigen3 was not found. 63 | Please specify the location of boost include directories 64 | via -DEIGEN3_INCLUDE option.") 65 | endif() 66 | endif() 67 | 68 | if (WITH_HDF5_SUPPORT) 69 | add_definitions(-D_HDF5) 70 | find_package(HDF5 COMPONENTS CXX) 71 | if (HDF5_FOUND) 72 | include_directories(${HDF5_INCLUDE_DIRS}) 73 | set(hdf5library ${HDF5_LIBRARIES}) 74 | else() 75 | if (HDF5_ROOT) 76 | include_directories("${HDF5_ROOT}/include") 77 | set(hdf5library "-L${HDF5_ROOT}/lib -lhdf5_cpp -lhdf5") 78 | else() 79 | message(FATAL_ERROR "HDF5 was not found. 80 | Please specify the HDF5 install directory 81 | via -DHDF5_ROOT option.") 82 | endif() 83 | endif() 84 | endif() 85 | 86 | # Version numbers 87 | file(READ ${PROJECT_SOURCE_DIR}/src/version.h version_file) 88 | string(REGEX MATCH "ALAMODE_VERSION = \"([0-9]+\\.[0-9]+\\.[0-9]+)\"" alm_version ${version_file}) 89 | set(alm_version ${CMAKE_MATCH_1}) 90 | MESSAGE("ALM version: ${CMAKE_MATCH_1}") 91 | set(serial "${alm_version}") 92 | set(soserial "1") 93 | 94 | # Source code 95 | include_directories("${PROJECT_SOURCE_DIR}/src") 96 | set(SOURCES ${PROJECT_SOURCE_DIR}/src/alm.cpp 97 | ${PROJECT_SOURCE_DIR}/src/cluster.cpp 98 | ${PROJECT_SOURCE_DIR}/src/constraint.cpp 99 | ${PROJECT_SOURCE_DIR}/src/fcs.cpp 100 | ${PROJECT_SOURCE_DIR}/src/files.cpp 101 | ${PROJECT_SOURCE_DIR}/src/input_parser.cpp 102 | ${PROJECT_SOURCE_DIR}/src/input_setter.cpp 103 | ${PROJECT_SOURCE_DIR}/src/optimize.cpp 104 | ${PROJECT_SOURCE_DIR}/src/patterndisp.cpp 105 | ${PROJECT_SOURCE_DIR}/src/rref.cpp 106 | ${PROJECT_SOURCE_DIR}/src/symmetry.cpp 107 | ${PROJECT_SOURCE_DIR}/src/system.cpp 108 | ${PROJECT_SOURCE_DIR}/src/timer.cpp 109 | ${PROJECT_SOURCE_DIR}/src/writer.cpp) 110 | 111 | set(HEADERS ${PROJECT_SOURCE_DIR}/src/alm.h 112 | ${PROJECT_SOURCE_DIR}/src/cluster.h 113 | ${PROJECT_SOURCE_DIR}/src/constraint.h 114 | ${PROJECT_SOURCE_DIR}/src/fcs.h 115 | ${PROJECT_SOURCE_DIR}/src/files.h 116 | ${PROJECT_SOURCE_DIR}/src/input_parser.h 117 | ${PROJECT_SOURCE_DIR}/src/input_setter.h 118 | ${PROJECT_SOURCE_DIR}/src/optimize.h 119 | ${PROJECT_SOURCE_DIR}/src/patterndisp.h 120 | ${PROJECT_SOURCE_DIR}/src/rref.h 121 | ${PROJECT_SOURCE_DIR}/src/symmetry.h 122 | ${PROJECT_SOURCE_DIR}/src/system.h 123 | ${PROJECT_SOURCE_DIR}/src/timer.h 124 | ${PROJECT_SOURCE_DIR}/src/writer.h) 125 | 126 | # # Trick to use gcc to compile *.cpp: This doesn't work because of boost 127 | # SET_SOURCE_FILES_PROPERTIES(${SOURCES} PROPERTIES LANGUAGE C) 128 | # set(CMAKE_C_COMPILER "gcc") 129 | 130 | # Executable 131 | add_executable(alm ${PROJECT_SOURCE_DIR}/src/main.cpp 132 | ${PROJECT_SOURCE_DIR}/src/alm_cui.cpp 133 | ${SOURCES} ${HEADERS}) 134 | 135 | target_link_libraries(alm ${Boost_LIBRARIES} ${LAPACK_LIBRARIES} ${spglib} ${openmplibrary}) 136 | if (WITH_HDF5_SUPPORT) 137 | target_link_libraries(alm ${hdf5library}) 138 | endif() 139 | 140 | # Shared library 141 | add_library(almcxx SHARED ${SOURCES}) 142 | target_link_libraries(almcxx ${Boost_LIBRARIES} ${LAPACK_LIBRARIES} ${spglib} ${openmplibrary}) 143 | if (WITH_HDF5_SUPPORT) 144 | target_link_libraries(almcxx ${hdf5library}) 145 | endif() 146 | set_property(TARGET almcxx PROPERTY VERSION ${serial}) 147 | set_property(TARGET almcxx PROPERTY SOVERSION ${soserial}) 148 | install(TARGETS almcxx DESTINATION ${PROJECT_SOURCE_DIR}/lib) 149 | 150 | # Static link library 151 | add_library(almcxx_static STATIC ${SOURCES}) 152 | set_property(TARGET almcxx_static PROPERTY VERSION ${serial}) 153 | set_property(TARGET almcxx_static PROPERTY SOVERSION ${soserial}) 154 | set_property(TARGET almcxx_static PROPERTY OUTPUT_NAME almcxx) 155 | install(TARGETS almcxx_static ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/lib) 156 | 157 | # Header file 158 | install(FILES ${PROJECT_SOURCE_DIR}/src/alm.h DESTINATION ${PROJECT_SOURCE_DIR}/include) 159 | -------------------------------------------------------------------------------- /CMakeLists.txt.conda: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | set(CMAKE_CXX_STANDARD 11) 3 | set(CMAKE_CXX_STANDARD_REQUIRED True) 4 | 5 | set(CMAKE_MACOSX_RPATH 1) 6 | set(CMAKE_CXX_FLAGS_RELEASE "-O2 -fopenmp") 7 | set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -O0 -D_DEBUG") 8 | #set(CMAKE_BUILD_TYPE DEBUG) 9 | set(CMAKE_BUILD_TYPE RELEASE) 10 | 11 | project(alm) 12 | 13 | if(WIN32) 14 | LINK_DIRECTORIES(C:\\lapack) 15 | LINK_DIRECTORIES(C:\\spglib) 16 | include_directories(C:\\spglib) 17 | set(LAPACK_LIBRARIES lapack) 18 | set(spglib symspg) 19 | endif() 20 | 21 | if (UNIX) 22 | include_directories($ENV{CONDA_PREFIX}/include) 23 | link_directories($ENV{CONDA_PREFIX}/lib) 24 | #set(ENV{BLA_VENDOR} "Intel10_64lp") 25 | #find_package(LAPACK REQUIRED) 26 | set(LAPACK_LIBRARIES "-llapack") 27 | #set(BLAS_LIBRARIES "-lopenblas") 28 | set(spglib "-lsymspg") 29 | endif() 30 | 31 | # 32 | # Add openmp flag if available 33 | # 34 | find_package(OpenMP) 35 | if (OPENMP_FOUND) 36 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 37 | set(openmp "-lgomp") 38 | else() 39 | set(openmp "-lomp") 40 | endif() 41 | 42 | find_package(Boost REQUIRED) 43 | include_directories(${Boost_INCLUDE_DIRS}) 44 | find_package(Eigen3 REQUIRED) 45 | include_directories(${EIGEN3_INCLUDE_DIR}) 46 | 47 | if (WITH_HDF5_SUPPORT) 48 | add_definitions(-D_HDF5) 49 | find_package(HDF5 REQUIRED COMPONENTS CXX) 50 | include_directories(${HDF5_INCLUDE_DIRS}) 51 | set(hdf5library ${HDF5_LIBRARIES}) 52 | endif() 53 | 54 | # Version numbers 55 | file(READ ${PROJECT_SOURCE_DIR}/src/version.h version_file) 56 | string(REGEX MATCH "ALAMODE_VERSION = \"([0-9]+\\.[0-9]+\\.[0-9]+)\"" alm_version ${version_file}) 57 | set(alm_version ${CMAKE_MATCH_1}) 58 | MESSAGE("ALM version: ${CMAKE_MATCH_1}") 59 | set(serial "${alm_version}") 60 | set(soserial "1") 61 | 62 | # Source code 63 | include_directories("${PROJECT_SOURCE_DIR}/src") 64 | set(SOURCES ${PROJECT_SOURCE_DIR}/src/alm.cpp 65 | ${PROJECT_SOURCE_DIR}/src/cluster.cpp 66 | ${PROJECT_SOURCE_DIR}/src/constraint.cpp 67 | ${PROJECT_SOURCE_DIR}/src/fcs.cpp 68 | ${PROJECT_SOURCE_DIR}/src/files.cpp 69 | ${PROJECT_SOURCE_DIR}/src/input_parser.cpp 70 | ${PROJECT_SOURCE_DIR}/src/input_setter.cpp 71 | ${PROJECT_SOURCE_DIR}/src/optimize.cpp 72 | ${PROJECT_SOURCE_DIR}/src/patterndisp.cpp 73 | ${PROJECT_SOURCE_DIR}/src/rref.cpp 74 | ${PROJECT_SOURCE_DIR}/src/symmetry.cpp 75 | ${PROJECT_SOURCE_DIR}/src/system.cpp 76 | ${PROJECT_SOURCE_DIR}/src/timer.cpp 77 | ${PROJECT_SOURCE_DIR}/src/writer.cpp) 78 | 79 | set(HEADERS ${PROJECT_SOURCE_DIR}/src/alm.h 80 | ${PROJECT_SOURCE_DIR}/src/cluster.h 81 | ${PROJECT_SOURCE_DIR}/src/constraint.h 82 | ${PROJECT_SOURCE_DIR}/src/fcs.h 83 | ${PROJECT_SOURCE_DIR}/src/files.h 84 | ${PROJECT_SOURCE_DIR}/src/input_parser.h 85 | ${PROJECT_SOURCE_DIR}/src/input_setter.h 86 | ${PROJECT_SOURCE_DIR}/src/optimize.h 87 | ${PROJECT_SOURCE_DIR}/src/patterndisp.h 88 | ${PROJECT_SOURCE_DIR}/src/rref.h 89 | ${PROJECT_SOURCE_DIR}/src/symmetry.h 90 | ${PROJECT_SOURCE_DIR}/src/system.h 91 | ${PROJECT_SOURCE_DIR}/src/timer.h 92 | ${PROJECT_SOURCE_DIR}/src/writer.h) 93 | 94 | # Executable 95 | add_executable(alm ${PROJECT_SOURCE_DIR}/src/main.cpp 96 | ${PROJECT_SOURCE_DIR}/src/alm_cui.cpp 97 | ${SOURCES} ${HEADERS}) 98 | target_link_libraries(alm ${Boost_LIBRARIES} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${spglib} ${openmp}) 99 | if (WITH_HDF5_SUPPORT) 100 | target_link_libraries(alm ${hdf5library}) 101 | endif() 102 | install(TARGETS alm DESTINATION ${PROJECT_SOURCE_DIR}/bin) 103 | 104 | # Shared library 105 | add_library(almcxx SHARED ${SOURCES}) 106 | target_link_libraries(almcxx ${Boost_LIBRARIES} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${spglib} ${openmp}) 107 | if (WITH_HDF5_SUPPORT) 108 | target_link_libraries(almcxx ${hdf5library}) 109 | endif() 110 | set_property(TARGET almcxx PROPERTY VERSION ${serial}) 111 | set_property(TARGET almcxx PROPERTY SOVERSION ${soserial}) 112 | install(TARGETS almcxx DESTINATION ${PROJECT_SOURCE_DIR}/lib) 113 | 114 | # Static link library 115 | add_library(almcxx_static STATIC ${SOURCES}) 116 | set_property(TARGET almcxx_static PROPERTY VERSION ${serial}) 117 | set_property(TARGET almcxx_static PROPERTY SOVERSION ${soserial}) 118 | set_property(TARGET almcxx_static PROPERTY OUTPUT_NAME almcxx) 119 | install(TARGETS almcxx_static ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/lib) 120 | 121 | # Header file 122 | install(FILES ${PROJECT_SOURCE_DIR}/src/alm.h DESTINATION ${PROJECT_SOURCE_DIR}/include) 123 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014,2015,2016 Terumasa Tadano 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ALM 2 | 3 | [![License][license-image]][license-url] 4 | [![Doc status][docs-image]][docs-url] 5 | [![Conda build](https://github.com/ttadano/ALM/actions/workflows/build-and-test-ALM-conda.yml/badge.svg)](https://github.com/ttadano/ALM/actions/workflows/build-and-test-ALM-conda.yml) 6 | 7 | ### Version 2.0.0 Dev 8 | 9 | - - - 10 | 11 | ## Introduction 12 | 13 | This is a software for calculating harmonic and anharmonic interatomic force constants in solids and molecules. 14 | 15 | ## Features 16 | 17 | * Extraction of harmonic and anharmonic force constants based on the supercell approach 18 | * Compressive sensing methods for an efficient and accurate estimation of force constants (LASSO, Elastic net) 19 | * Applicable to any crystal structures and low-dimensional systems 20 | * Accurate treatment of translational and rotational invariance 21 | * Interface to VASP, Quantum-ESPRESSO, OpenMX, xTAPP, and LAMMPS codes 22 | * API for python and C++ 23 | 24 | ## License 25 | Copyright (c) 2014 Terumasa Tadano 26 | This software is released under the MIT license. 27 | For license rights and limitations, see LICENSE.txt file. 28 | 29 | ## Author 30 | * Terumasa Tadano 31 | * Atsushi Togo 32 | 33 | 34 | [license-image]: https://img.shields.io/github/license/ttadano/ALM.svg 35 | [license-url]: https://github.com/ttadano/ALM/blob/develop/LICENSE.txt 36 | 37 | [docs-image]: https://readthedocs.org/projects/alm/badge/?version=develop 38 | [docs-url]: https://alm.readthedocs.io/en/develop/?badge=develop 39 | 40 | [travis-image]: https://travis-ci.org/ttadano/ALM.svg?branch=develop 41 | [travis-url]: https://travis-ci.org/ttadano/ALM 42 | -------------------------------------------------------------------------------- /conda/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd python 4 | 5 | export CPLUS_INCLUDE_PATH=$CONDA_PREFIX/include:$CONDA_PREFIX/include/eigen3 6 | export LIBRARY_PATH=$CONDA_PREFIX/lib:${LIBRARY_PATH} 7 | export CC=${CXX} 8 | export LDFLAGS="-fopenmp -lblas" 9 | 10 | $PYTHON setup.py install --single-version-externally-managed --record record.txt 11 | 12 | -------------------------------------------------------------------------------- /conda/meta.yaml: -------------------------------------------------------------------------------- 1 | {% set name = "ALM" %} 2 | {% set version = "1.0.2" %} 3 | {% set sha256 = "96a2633b06ead6110784dba79d5b549bf1161dcf2cc0200f4f92b62c9bebdaed" %} 4 | 5 | package: 6 | name: {{ name|lower }} 7 | version: {{ version }} 8 | 9 | source: 10 | #url: https://github.com/jochym/{{ name }}/archive/v{{ version }}.tar.gz 11 | #sha256: {{ sha256 }} 12 | git_url: https://github.com/jochym/ALM.git 13 | git_tag: package 14 | 15 | build: 16 | number: 0 17 | skip: True # [win] 18 | 19 | requirements: 20 | build: 21 | - {{ compiler('c') }} 22 | - {{ compiler('cxx') }} 23 | - cmake 24 | - eigen 25 | host: 26 | - python 27 | - blas 1.1 openblas # [unix] 28 | - boost 29 | - numpy 30 | - spglib >=1.11.1.2 31 | - setuptools 32 | run: 33 | - python 34 | - blas 1.1 openblas # [unix] 35 | - spglib >=1.11.1.2 36 | 37 | test: 38 | source_files: 39 | - test/*.dat 40 | - test/*.py 41 | requires: 42 | - numpy 43 | imports: 44 | - alm 45 | commands: 46 | - cd test 47 | - python Si_fitting.py 48 | - python SiC_fitting.py 49 | 50 | about: 51 | home: https://github.com/ttadano/ALM 52 | license: MIT 53 | license_family: MIT 54 | license_file: LICENSE.txt 55 | summary: 'Software for calculating harmonic and anharmonic interatomic force constants in solids and molecules.' 56 | 57 | description: | 58 | ALM can be used for Extraction of harmonic and anharmonic force constants 59 | based on the supercell approach. It is applicable to any crystal structure 60 | and low-dimensional systems. Features accurate treatment of translational 61 | and rotational invariance and Interface to VASP, Quantum-ESPRESSO, and xTAPP. 62 | doc_url: http://alm.readthedocs.io/ 63 | dev_url: https://github.com/ttadano/ALM 64 | 65 | extra: 66 | recipe-maintainers: 67 | - jochym 68 | -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ttadano/ALM/f1d668fdee66e7e7218a04c88daf19d0e14fce0c/docs/.nojekyll -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = python -msphinx 7 | SPHINXPROJ = ALM 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /docs/alm.rst: -------------------------------------------------------------------------------- 1 | alm package 2 | =========== 3 | 4 | Submodules 5 | ---------- 6 | 7 | alm.alm module 8 | -------------- 9 | 10 | .. automodule:: alm.alm 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | alm.fcsxml module 16 | ----------------- 17 | 18 | .. automodule:: alm.fcsxml 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: alm 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/compile-with-conda-packages.rst: -------------------------------------------------------------------------------- 1 | .. _compile_with_conda_packages: 2 | 3 | Building ALM using conda 4 | ========================= 5 | 6 | ALM is written in C++. To build it, a set of build tools is 7 | needed. Currently using conda gives a relatively simple and uniform 8 | way to perform building the ALM python module, ALM library for 9 | C++, and ALMM command executable. In this documentation, it is 10 | presented a step-by-step procedure to build them using conda. 11 | 12 | .. contents:: 13 | :depth: 2 14 | :local: 15 | 16 | Preparing build tools by conda 17 | ------------------------------- 18 | 19 | At first, it is recommended `to prepare a conda environment 20 | `_ by:: 21 | 22 | % conda create --name alm -c conda-forge 23 | 24 | Here the name of the conda environment is chosen ``alm``. The detailed 25 | instruction about the conda environment is found `here 26 | `_. 27 | To build ALM on linux or macOS, the following conda packages are 28 | installed by 29 | 30 | :: 31 | 32 | % conda install -c conda-forge numpy scipy h5py compilers "libblas=*=*mkl" spglib boost eigen cmake ipython mkl-include 33 | 34 | If one wants to use other BLAS libraries than MKL, the package 35 | ``libblas=*=*mkl`` should be replaced by the appropriate package name, e.g., ``libblas=*=*openblas``. 36 | 37 | .. _build_ALMlib: 38 | 39 | Building ALM 40 | ------------- 41 | 42 | Now the directory structure supposed in this document is shown as below:: 43 | 44 | $HOME 45 | |-- alm 46 | | `-- ALM 47 | | |-- bin/ 48 | | |-- include/ 49 | | |-- lib/ 50 | | |-- python/setup.py 51 | | |-- src/ 52 | | |-- _build/ 53 | | |-- CMakeLists.txt 54 | | |-- CMakeLists.txt.conda 55 | | `-- ... 56 | | 57 | |-- $CONDA_PREFIX/include 58 | |-- $CONDA_PREFIX/include/eigen3 59 | |-- $CONDA_PREFIX/lib 60 | `-- ... 61 | 62 | ``alm`` directory is created by us and we move to this directory. Now 63 | we are in ``$HOME/alm``. In this direcotry, ALM is downloaded from 64 | github. ``ALM`` directorie is created running the following commands:: 65 | 66 | % git clone https://github.com/ttadano/ALM.git 67 | 68 | Make sure that you are using develop branch by 69 | 70 | :: 71 | 72 | % cd ALM 73 | % git branch 74 | * develop 75 | 76 | When this is done on ``$HOME/ALM``, the above directory structure is 77 | made. If git command doesn't exist in your system, it is also obtained 78 | from conda by ``conda install git``. 79 | 80 | Building ALM python module 81 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 82 | 83 | The ALM python module is built on the directory 84 | ``$HOME/alm/ALM/python``. So first you have to move to this directory. 85 | The build and installation in the user directory is done by 86 | 87 | :: 88 | 89 | % python -m pip install . 90 | 91 | .. 92 | For macOS, we use clang instead of gcc in this documentation. In this 93 | case, ALM python module must be compiled by clang++ 94 | command but not clang command. To let python `setuptools 95 | `_ choose the C++ 96 | compiler installed using conda, the environment variables ``CC`` is 97 | overwritten by ``CXX`` by 98 | 99 | :: 100 | 101 | % export CC=$CXX 102 | 103 | and libomp is used as the OpenMP library, which is set in ``setup.py`` 104 | 105 | extra_link_args = ['-lomp'] 106 | 107 | 108 | Building ALM executable and C++ library 109 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 110 | 111 | If you need only ALM python module, this section can be skipped. 112 | 113 | Let's assume we are in the directory ``$HOME/alm/ALM`` (see above 114 | :ref:`directory structure `). The ALM 115 | library for C++ is built using cmake. The cmake's configuration file 116 | has to have the filename ``CMakeLists.txt``. So its example of 117 | ``CMakeLists.txt.conda`` is renamed to ``CMakeLists.txt``, i.e., 118 | 119 | :: 120 | 121 | % cp CMakeLists.txt.conda CMakeLists.txt 122 | 123 | Then this ``CMakeLists.txt`` may be modified appropriately when the 124 | following compilation fails. 125 | Using this ``CMakeLists.txt``, the ALM library for c++ is built for Linux by 126 | 127 | :: 128 | 129 | % mkdir _build && cd _build 130 | % cmake .. 131 | % make -j4 132 | % make install 133 | 134 | and for macOS 135 | 136 | :: 137 | 138 | % mkdir _build && cd _build 139 | % cmake -DCMAKE_C_COMPILER='clang' -DCMAKE_CXX_COMPILER='clang++' .. 140 | % make -j4 141 | % make install 142 | 143 | To see detailed make log, ``-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON`` option 144 | for ``cmake`` should be added. 145 | 146 | The dynamic and static link libraries and the head file are installed 147 | at 148 | 149 | - ``$HOME/alm/ALM/lib/libalmcxx.dylib`` or ``$HOME/alm/ALM/lib/libalmcxx.so`` 150 | - ``$HOME/alm/ALM/lib/libalmcxx.a`` 151 | - ``$HOME/alm/ALM/include/alm.h`` 152 | 153 | The executable is found at 154 | 155 | - ``$HOME/alm/ALM/bin/alm`` 156 | 157 | To use the dynamic link library, it may be necessary to set 158 | ``$LD_LIBRARY_PATH`` to 159 | 160 | :: 161 | 162 | % export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$HOME/alm/ALM/lib:$LD_LIBRARY_PATH 163 | 164 | and to use the executable 165 | 166 | :: 167 | 168 | % export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH 169 | -------------------------------------------------------------------------------- /docs/compile-with-makefile.rst: -------------------------------------------------------------------------------- 1 | 2 | Building ALM using Makefile 3 | =========================== 4 | 5 | ALM can also be built with the Makefile in the ``src`` subdirectory. 6 | This approach only generates the command line version of ALM (binary ``alm``). 7 | Therefore, if you want to use ALM from python as well, please 8 | :ref:`build ALM using conda `. 9 | 10 | Requirement 11 | ----------- 12 | 13 | * C++ compiler (C++11 standard or newer) 14 | * LAPACK 15 | * `Boost C++ library `_ 16 | * `Eigen3 library `_ 17 | * `spglib `_ 18 | 19 | How to install 20 | -------------- 21 | 22 | .. highlight:: bash 23 | 24 | 1. Install the LAPACK, Boost C++, and Eigen3, and spglib. 25 | 26 | To install the Boost C++ library, please download a source file from the `website `_ and 27 | unpack the file. Then, copy the 'boost' subdirectory to the include folder in the home directory (or anywhere you like). 28 | This can be done as follows:: 29 | 30 | $ cd 31 | $ mkdir etc; cd etc 32 | (Download a source file and mv it to ~/etc) 33 | $ tar xvf boost_x_yy_z.tar.bz2 34 | $ cd ../ 35 | $ mkdir include; cd include 36 | $ ln -s ../etc/boost_x_yy_z/boost . 37 | 38 | In this example, we made a symbolic link to the 'boost' subdirectory in ``$HOME/include``. 39 | Instead of installing from source, you can install the Boost library with `Homebrew `_ on Mac. 40 | 41 | In the same way, please install the Eigen3 include files as follows:: 42 | 43 | $ cd 44 | $ mkdir etc; cd etc 45 | (Download a source file and mv it to ~/etc) 46 | $ tar xvf eigen-eigen-*.tar.bz2 (* is an array of letters and digits) 47 | $ cd ../ 48 | $ cd include 49 | $ ln -s ../etc/eigen-eigen-*/Eigen . 50 | 51 | 2. Clone ALM from the git repository and edit Makefile:: 52 | 53 | $ git clone https://github.com/ttadano/ALM 54 | $ cd ALM/src/ 55 | (Edit Makefile.linux or Makefile.osx) 56 | $ make -f Makefile.linux -j (or make -j Makefile.osx -j) 57 | 58 | In the ``src`` directory, we provide sample Makefiles for linux (Intel compiler) and MacOS (GCC installed via homebrew) as shown below. 59 | 60 | .. literalinclude:: ../src/Makefile.linux 61 | :caption: **Makefile.linux** 62 | :language: makefile 63 | :linenos: 64 | :lines: 7-17 65 | 66 | .. literalinclude:: ../src/Makefile.osx 67 | :caption: **Makefile.osx** 68 | :language: makefile 69 | :linenos: 70 | :lines: 7-18 71 | 72 | 3. Modify ``LD_LIBRARY_PATH`` as follows:: 73 | 74 | bash, zsh 75 | $ export LD_LIBRARY_PATH=$(HOME)/src/spglib/lib:$LD_LIBRARY_PATH 76 | 77 | csh, tcsh 78 | $ setenv LD_LIBRARY_PATH $(HOME)/src/spglib/lib:$LD_LIBRARY_PATH 79 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # ALM documentation build configuration file, created by 5 | # sphinx-quickstart on Wed Sep 26 00:04:55 2018. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | # 20 | import os 21 | import sys 22 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) 23 | #sys.path.insert(0, os.path.abspath('../python/alm')) 24 | #sys.path.insert(0, os.path.abspath('../python')) 25 | #sys.path.insert(0, os.path.abspath('..')) 26 | 27 | # -- General configuration ------------------------------------------------ 28 | 29 | # If your documentation needs a minimal Sphinx version, state it here. 30 | # 31 | # needs_sphinx = '1.0' 32 | 33 | # Add any Sphinx extension module names here, as strings. They can be 34 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 35 | # ones. 36 | extensions = ['sphinx.ext.autodoc', 'sphinx.ext.mathjax', 37 | 'sphinx.ext.napoleon'] 38 | 39 | def run_apidoc(_): 40 | from sphinx.ext.apidoc import main 41 | #from sphinx.apidoc import main 42 | parentFolder = os.path.join(os.path.dirname(__file__), '..') 43 | cur_dir = os.path.abspath(os.path.dirname(__file__)) 44 | print(sys.path) 45 | module = os.path.join(parentFolder,'python','alm') 46 | output_path = '.' 47 | main(['-f','-o', output_path, module]) 48 | 49 | def setup(app): 50 | # overrides for wide tables in RTD theme 51 | app.add_css_file('theme_overrides.css') 52 | # trigger the run_apidoc 53 | app.connect('builder-inited', run_apidoc) 54 | 55 | autoclass_content = 'both' 56 | # Add any paths that contain templates here, relative to this directory. 57 | templates_path = ['_templates'] 58 | 59 | # The suffix(es) of source filenames. 60 | # You can specify multiple suffix as a list of string: 61 | # 62 | # source_suffix = ['.rst', '.md'] 63 | source_suffix = '.rst' 64 | 65 | # The master toctree document. 66 | master_doc = 'index' 67 | 68 | # General information about the project. 69 | project = 'ALM' 70 | copyright = '2018, Terumasa Tadano' 71 | author = 'Terumasa Tadano' 72 | 73 | # The version info for the project you're documenting, acts as replacement for 74 | # |version| and |release|, also used in various other places throughout the 75 | # built documents. 76 | # 77 | # The short X.Y version. 78 | version = '2.0' 79 | # The full version, including alpha/beta/rc tags. 80 | release = '2.0.0 beta' 81 | 82 | # The language for content autogenerated by Sphinx. Refer to documentation 83 | # for a list of supported languages. 84 | # 85 | # This is also used if you do content translation via gettext catalogs. 86 | # Usually you set "language" from the command line for these cases. 87 | language = 'en' 88 | 89 | # List of patterns, relative to source directory, that match files and 90 | # directories to ignore when looking for source files. 91 | # This patterns also effect to html_static_path and html_extra_path 92 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 93 | 94 | # The name of the Pygments (syntax highlighting) style to use. 95 | pygments_style = 'sphinx' 96 | 97 | # If true, `todo` and `todoList` produce output, else they produce nothing. 98 | todo_include_todos = False 99 | 100 | 101 | # -- Options for HTML output ---------------------------------------------- 102 | 103 | # The theme to use for HTML and HTML Help pages. See the documentation for 104 | # a list of builtin themes. 105 | # 106 | html_theme = 'sphinx_rtd_theme' 107 | 108 | # Theme options are theme-specific and customize the look and feel of a theme 109 | # further. For a list of options available for each theme, see the 110 | # documentation. 111 | # 112 | # html_theme_options = {} 113 | 114 | # Add any paths that contain custom static files (such as style sheets) here, 115 | # relative to this directory. They are copied after the builtin static files, 116 | # so a file named "default.css" will overwrite the builtin "default.css". 117 | html_static_path = ['_static'] 118 | 119 | # Custom sidebar templates, must be a dictionary that maps document names 120 | # to template names. 121 | # 122 | # This is required for the alabaster theme 123 | # refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars 124 | html_sidebars = { 125 | '**': [ 126 | 'about.html', 127 | 'navigation.html', 128 | 'relations.html', # needs 'show_related': True theme option to display 129 | 'searchbox.html', 130 | 'donate.html', 131 | ] 132 | } 133 | 134 | 135 | # -- Options for HTMLHelp output ------------------------------------------ 136 | 137 | # Output file base name for HTML help builder. 138 | htmlhelp_basename = 'ALMdoc' 139 | 140 | 141 | # -- Options for LaTeX output --------------------------------------------- 142 | 143 | latex_elements = { 144 | # The paper size ('letterpaper' or 'a4paper'). 145 | # 146 | # 'papersize': 'letterpaper', 147 | 148 | # The font size ('10pt', '11pt' or '12pt'). 149 | # 150 | # 'pointsize': '10pt', 151 | 152 | # Additional stuff for the LaTeX preamble. 153 | # 154 | # 'preamble': '', 155 | 156 | # Latex figure (float) alignment 157 | # 158 | # 'figure_align': 'htbp', 159 | } 160 | 161 | # Grouping the document tree into LaTeX files. List of tuples 162 | # (source start file, target name, title, 163 | # author, documentclass [howto, manual, or own class]). 164 | latex_documents = [ 165 | (master_doc, 'ALM.tex', 'ALM Documentation', 166 | 'Terumasa Tadano', 'manual'), 167 | ] 168 | 169 | 170 | # -- Options for manual page output --------------------------------------- 171 | 172 | # One entry per manual page. List of tuples 173 | # (source start file, name, description, authors, manual section). 174 | man_pages = [ 175 | (master_doc, 'alm', 'ALM Documentation', 176 | [author], 1) 177 | ] 178 | 179 | 180 | # -- Options for Texinfo output ------------------------------------------- 181 | 182 | # Grouping the document tree into Texinfo files. List of tuples 183 | # (source start file, target name, title, author, 184 | # dir menu entry, description, category) 185 | texinfo_documents = [ 186 | (master_doc, 'ALM', 'ALM Documentation', 187 | author, 'ALM', 'One line description of project.', 188 | 'Miscellaneous'), 189 | ] 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/format-dfset.rst: -------------------------------------------------------------------------------- 1 | How to make a DFSET file 2 | ------------------------ 3 | 4 | .. _label_format_DFILE: 5 | 6 | Format of ``DFSET`` 7 | ~~~~~~~~~~~~~~~~~~~ 8 | 9 | The displacement-force data sets obtained by first-principles (or classical force-field) calculations 10 | have to be saved to a file, say *DFSET*. Then, the force constants are estimated by setting ``DFSET =`` *DFSET* and with ``MODE = optimize``. 11 | 12 | The *DFSET* file must contain the atomic displacements and corresponding forces in Cartesian coordinate for at least ``NDATA`` structures (displacement patterns) 13 | in the following format: 14 | 15 | .. math:: 16 | :nowrap: 17 | 18 | # Structure number 1 (this is just a comment line) 19 | \begin{eqnarray*} 20 | u_{x}(1) & u_{y}(1) & u_{z}(1) & f_{x}(1) & f_{y}(1) & f_{z}(1) \\ 21 | u_{x}(2) & u_{y}(2) & u_{z}(2) & f_{x}(2) & f_{y}(2) & f_{z}(2) \\ 22 | & \vdots & & & \vdots & \\ 23 | u_{x}(\mathrm{NAT}) & u_{y}(\mathrm{NAT}) & u_{z}(\mathrm{NAT}) & f_{x}(\mathrm{NAT}) & f_{y}(\mathrm{NAT}) & f_{z}(\mathrm{NAT}) 24 | \end{eqnarray*} 25 | # Structure number 2 26 | \begin{eqnarray*} 27 | u_{x}(1) & u_{y}(1) & u_{z}(1) & f_{x}(1) & f_{y}(1) & f_{z}(1) \\ 28 | & \vdots & & & \vdots & 29 | \end{eqnarray*} 30 | 31 | Here, ``NAT`` is the number of atoms in the supercell. 32 | The unit of displacements and forces must be **Bohr** and **Ryd/Bohr**, respectively. 33 | 34 | 35 | Generation of ``DFSET`` by extract.py 36 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 37 | 38 | The script ``extract.py`` in the tools directory of ALM is useful to generate ``DFSET`` files from output files of some popular DFT codes. 39 | Let us assume that we have calculated atomic forces for 10 different structures by VASP and saved the results as vasprun_01.xml ... vasprun_10.xml. 40 | Then, a ``DFSET`` file can be generated as: 41 | 42 | **VASP** 43 | :: 44 | 45 | $ python extract.py --VASP=SPOSCAR --offset=vasprun0.xml vasprun??.xml > DFSET 46 | 47 | Here, ``SPOSCAR`` is the supercell structure without atomic displacements, and vasprun0.xml is the result of DFT calculation for ``SPOSCAR``. 48 | The ``--offset`` option subtract the offset (residual) components of atomic forces from the data in vasprun??.xml. 49 | 50 | .. important:: 51 | The ``--offset`` is optional, but we strongly recommend to use it when the fractional coordinates of atoms have degrees of freedom. 52 | 53 | The ``extract.py`` can also parse the data from the output files of QE, OpenMX, xTAPP, and LAMMPS: 54 | 55 | **QE** 56 | :: 57 | 58 | $ python extract.py --QE=supercell.pw.in --offset=supercell.pw.out disp??.pw.out > DFSET 59 | 60 | **OpenMX** 61 | :: 62 | 63 | $ python extract.py --OpenMX=supercell.dat --offset=supercell.out disp??.out > DFSET 64 | 65 | **xTAPP** 66 | :: 67 | 68 | $ python extract.py --xTAPP=supercell.cg --offset=supercell.str disp??.str > DFSET 69 | 70 | **LAMMPS** 71 | 72 | The LAMMPS case requires a special treatment. We first need to add the *dump* option in the LAMMPS input file as 73 | :: 74 | 75 | dump 1 all custom 1 XFSET id xu xy xz fx fy fz 76 | dump_modify 1 format float "%20.15f" 77 | 78 | This option will generate the file *XFSET* which contains atomic coordinates and forces. 79 | After generating *XFSET* files for 10 structures and save them as *XFSET.01* ... *XFSET.10* , we can create ``DFSET`` as: 80 | :: 81 | 82 | $ python extract.py --LAMMPS=supercell.lammps --offset=supercell.XFSET XFSET.?? > DFSET -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. ALM documentation master file, created by 2 | sphinx-quickstart on Wed Sep 26 00:04:55 2018. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to ALM's documentation! 7 | =============================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | :caption: Contents: 12 | 13 | intro 14 | compile-with-conda-packages 15 | compile-with-makefile 16 | input-tags 17 | python-module 18 | format-dfset 19 | formalism 20 | modules 21 | 22 | 23 | 24 | Indices and tables 25 | ================== 26 | 27 | * :ref:`genindex` 28 | * :ref:`modindex` 29 | * :ref:`search` 30 | -------------------------------------------------------------------------------- /docs/intro.rst: -------------------------------------------------------------------------------- 1 | .. raw:: html 2 | 3 | 11 | 12 | 13 | About 14 | ===== 15 | 16 | What is ALM? 17 | ----------------- 18 | 19 | **ALM** is an open source software designed for estimating harmonic and anharmonic force constants based on the supercell method. 20 | 21 | Features 22 | -------- 23 | 24 | * Extraction of harmonic and anharmonic force constants based on the supercell approach 25 | * Applicable to any crystal structures and low-dimensional systems 26 | * Accurate treatment of translational and rotational invariance 27 | * Interface to VASP, Quantum-ESPRESSO, xTAPP, and LAMMPS codes 28 | * API for python and C++ 29 | 30 | Links 31 | ----- 32 | 33 | * Documentation : http://alm.readthedocs.io (this page) 34 | * Git repository : http://github.com/ttadano/ALM 35 | 36 | 37 | License 38 | ------- 39 | 40 | .. |copy| unicode:: U+000A9 41 | 42 | Copyright |copy| 2014--2018 Terumasa Tadano 43 | 44 | This software is distributed under the MIT license. 45 | See the LICENSE.txt file for license rights and limitations. 46 | 47 | 48 | How to Cite ALM 49 | --------------- 50 | 51 | Please cite the following article when you use ALM in : 52 | 53 | T\. Tadano, XXX, XXX **XX**\ , XXXX (XXXX) 54 | 55 | Acknowledgement 56 | --------------- 57 | 58 | This project is/was partially supported by the following projects: 59 | 60 | * Grant-in-Aid for Young Scientists (B) (16K17724) 61 | * Grant-in-Aid for Scientific Research on Innovative Areas 'Materials Design through Computics: Complex Correlation and Non-Equilibrium Dynamics'. (http://computics-material.jp) 62 | 63 | 64 | Author & Contact 65 | ---------------- 66 | 67 | .. raw:: html 68 | 69 | 70 | 71 | | International Center for Young Scientists (ICYS), 72 | | National Institute for Material Science (NIMS), 73 | | Japan 74 | 75 | -------------------------------------------------------------------------------- /docs/modules.rst: -------------------------------------------------------------------------------- 1 | alm 2 | === 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | alm 8 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx==7.1.2 2 | sphinx-rtd-theme==1.3.0rc1 3 | -------------------------------------------------------------------------------- /etc/alm-environment.yml: -------------------------------------------------------------------------------- 1 | name: alm 2 | 3 | channels: 4 | - conda-forge 5 | 6 | dependencies: 7 | - numpy 8 | - scipy 9 | - h5py 10 | - compilers 11 | - spglib 12 | - boost 13 | - eigen 14 | - cmake 15 | -------------------------------------------------------------------------------- /example/AlN/DFSET_AlN.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ttadano/ALM/f1d668fdee66e7e7218a04c88daf19d0e14fce0c/example/AlN/DFSET_AlN.lzma -------------------------------------------------------------------------------- /example/AlN/POSCAR_AlN: -------------------------------------------------------------------------------- 1 | generated by phonopy 2 | 1.0 3 | 9.3329999969514006 0.0000000000000000 0.0000000000000000 4 | -4.6664999984757003 8.0826150908799992 0.0000000000000000 5 | 0.0000000000000000 0.0000000000000000 9.9559999999999995 6 | Al N 7 | 36 36 8 | Direct 9 | 0.1111111111111100 0.2222222222222190 0.4995255900000000 10 | 0.4444444444444430 0.2222222222222190 0.4995255900000000 11 | 0.7777777777777760 0.2222222222222190 0.4995255900000000 12 | 0.1111111111111140 0.5555555555555610 0.4995255900000000 13 | 0.4444444444444470 0.5555555555555610 0.4995255900000000 14 | 0.7777777777777810 0.5555555555555610 0.4995255900000000 15 | 0.1111111111111120 0.8888888888888899 0.4995255900000000 16 | 0.4444444444444450 0.8888888888888899 0.4995255900000000 17 | 0.7777777777777790 0.8888888888888899 0.4995255900000000 18 | 0.1111111111111100 0.2222222222222190 0.9995255900000000 19 | 0.4444444444444430 0.2222222222222190 0.9995255900000000 20 | 0.7777777777777760 0.2222222222222190 0.9995255900000000 21 | 0.1111111111111140 0.5555555555555610 0.9995255900000000 22 | 0.4444444444444470 0.5555555555555610 0.9995255900000000 23 | 0.7777777777777810 0.5555555555555610 0.9995255900000000 24 | 0.1111111111111120 0.8888888888888899 0.9995255900000000 25 | 0.4444444444444450 0.8888888888888899 0.9995255900000000 26 | 0.7777777777777790 0.8888888888888899 0.9995255900000000 27 | 0.2222222222222230 0.1111111111111120 0.2495255900000000 28 | 0.5555555555555560 0.1111111111111120 0.2495255900000000 29 | 0.8888888888888899 0.1111111111111120 0.2495255900000000 30 | 0.2222222222222260 0.4444444444444510 0.2495255900000000 31 | 0.5555555555555590 0.4444444444444510 0.2495255900000000 32 | 0.8888888888888919 0.4444444444444510 0.2495255900000000 33 | 0.2222222222222240 0.7777777777777810 0.2495255900000000 34 | 0.5555555555555570 0.7777777777777810 0.2495255900000000 35 | 0.8888888888888899 0.7777777777777810 0.2495255900000000 36 | 0.2222222222222230 0.1111111111111120 0.7495255900000000 37 | 0.5555555555555560 0.1111111111111120 0.7495255900000000 38 | 0.8888888888888899 0.1111111111111120 0.7495255900000000 39 | 0.2222222222222260 0.4444444444444510 0.7495255900000000 40 | 0.5555555555555590 0.4444444444444510 0.7495255900000000 41 | 0.8888888888888919 0.4444444444444510 0.7495255900000000 42 | 0.2222222222222240 0.7777777777777810 0.7495255900000000 43 | 0.5555555555555570 0.7777777777777810 0.7495255900000000 44 | 0.8888888888888899 0.7777777777777810 0.7495255900000000 45 | 0.1111111111111100 0.2222222222222190 0.1904744100000000 46 | 0.4444444444444430 0.2222222222222190 0.1904744100000000 47 | 0.7777777777777760 0.2222222222222190 0.1904744100000000 48 | 0.1111111111111140 0.5555555555555610 0.1904744100000000 49 | 0.4444444444444470 0.5555555555555610 0.1904744100000000 50 | 0.7777777777777810 0.5555555555555610 0.1904744100000000 51 | 0.1111111111111120 0.8888888888888899 0.1904744100000000 52 | 0.4444444444444450 0.8888888888888899 0.1904744100000000 53 | 0.7777777777777790 0.8888888888888899 0.1904744100000000 54 | 0.1111111111111100 0.2222222222222190 0.6904744100000000 55 | 0.4444444444444430 0.2222222222222190 0.6904744100000000 56 | 0.7777777777777760 0.2222222222222190 0.6904744100000000 57 | 0.1111111111111140 0.5555555555555610 0.6904744100000000 58 | 0.4444444444444470 0.5555555555555610 0.6904744100000000 59 | 0.7777777777777810 0.5555555555555610 0.6904744100000000 60 | 0.1111111111111120 0.8888888888888899 0.6904744100000000 61 | 0.4444444444444450 0.8888888888888899 0.6904744100000000 62 | 0.7777777777777790 0.8888888888888899 0.6904744100000000 63 | 0.2222222222222230 0.1111111111111120 0.4404744100000000 64 | 0.5555555555555560 0.1111111111111120 0.4404744100000000 65 | 0.8888888888888899 0.1111111111111120 0.4404744100000000 66 | 0.2222222222222260 0.4444444444444510 0.4404744100000000 67 | 0.5555555555555590 0.4444444444444510 0.4404744100000000 68 | 0.8888888888888919 0.4444444444444510 0.4404744100000000 69 | 0.2222222222222240 0.7777777777777810 0.4404744100000000 70 | 0.5555555555555570 0.7777777777777810 0.4404744100000000 71 | 0.8888888888888899 0.7777777777777810 0.4404744100000000 72 | 0.2222222222222230 0.1111111111111120 0.9404744100000000 73 | 0.5555555555555560 0.1111111111111120 0.9404744100000000 74 | 0.8888888888888899 0.1111111111111120 0.9404744100000000 75 | 0.2222222222222260 0.4444444444444510 0.9404744100000000 76 | 0.5555555555555590 0.4444444444444510 0.9404744100000000 77 | 0.8888888888888919 0.4444444444444510 0.9404744100000000 78 | 0.2222222222222240 0.7777777777777810 0.9404744100000000 79 | 0.5555555555555570 0.7777777777777810 0.9404744100000000 80 | 0.8888888888888899 0.7777777777777810 0.9404744100000000 81 | -------------------------------------------------------------------------------- /example/AlN/README: -------------------------------------------------------------------------------- 1 | DFSET_AlN can be extracted from DFSET_AlN.lzma wth GNU tar by 2 | 3 | % tar xvfa DFSET_AlN.lzma 4 | 5 | With BSD command 6 | 7 | % tar xvfz DFSET_AlN.lzma 8 | -------------------------------------------------------------------------------- /example/Si_fitting.py: -------------------------------------------------------------------------------- 1 | # 2 | # Si_fitting.py 3 | # # This is an example to run ALM in the fitting mode. 4 | # 5 | 6 | from alm import ALM 7 | import numpy as np 8 | 9 | lavec = [[20.406, 0, 0], 10 | [0, 20.406, 0], 11 | [0, 0, 20.406]] 12 | xcoord = [[0.0000000000000000, 0.0000000000000000, 0.0000000000000000], 13 | [0.0000000000000000, 0.0000000000000000, 0.5000000000000000], 14 | [0.0000000000000000, 0.2500000000000000, 0.2500000000000000], 15 | [0.0000000000000000, 0.2500000000000000, 0.7500000000000000], 16 | [0.0000000000000000, 0.5000000000000000, 0.0000000000000000], 17 | [0.0000000000000000, 0.5000000000000000, 0.5000000000000000], 18 | [0.0000000000000000, 0.7500000000000000, 0.2500000000000000], 19 | [0.0000000000000000, 0.7500000000000000, 0.7500000000000000], 20 | [0.1250000000000000, 0.1250000000000000, 0.1250000000000000], 21 | [0.1250000000000000, 0.1250000000000000, 0.6250000000000000], 22 | [0.1250000000000000, 0.3750000000000000, 0.3750000000000000], 23 | [0.1250000000000000, 0.3750000000000000, 0.8750000000000000], 24 | [0.1250000000000000, 0.6250000000000000, 0.1250000000000000], 25 | [0.1250000000000000, 0.6250000000000000, 0.6250000000000000], 26 | [0.1250000000000000, 0.8750000000000000, 0.3750000000000000], 27 | [0.1250000000000000, 0.8750000000000000, 0.8750000000000000], 28 | [0.2500000000000000, 0.0000000000000000, 0.2500000000000000], 29 | [0.2500000000000000, 0.0000000000000000, 0.7500000000000000], 30 | [0.2500000000000000, 0.2500000000000000, 0.0000000000000000], 31 | [0.2500000000000000, 0.2500000000000000, 0.5000000000000000], 32 | [0.2500000000000000, 0.5000000000000000, 0.2500000000000000], 33 | [0.2500000000000000, 0.5000000000000000, 0.7500000000000000], 34 | [0.2500000000000000, 0.7500000000000000, 0.0000000000000000], 35 | [0.2500000000000000, 0.7500000000000000, 0.5000000000000000], 36 | [0.3750000000000000, 0.1250000000000000, 0.3750000000000000], 37 | [0.3750000000000000, 0.1250000000000000, 0.8750000000000000], 38 | [0.3750000000000000, 0.3750000000000000, 0.1250000000000000], 39 | [0.3750000000000000, 0.3750000000000000, 0.6250000000000000], 40 | [0.3750000000000000, 0.6250000000000000, 0.3750000000000000], 41 | [0.3750000000000000, 0.6250000000000000, 0.8750000000000000], 42 | [0.3750000000000000, 0.8750000000000000, 0.1250000000000000], 43 | [0.3750000000000000, 0.8750000000000000, 0.6250000000000000], 44 | [0.5000000000000000, 0.0000000000000000, 0.0000000000000000], 45 | [0.5000000000000000, 0.0000000000000000, 0.5000000000000000], 46 | [0.5000000000000000, 0.2500000000000000, 0.2500000000000000], 47 | [0.5000000000000000, 0.2500000000000000, 0.7500000000000000], 48 | [0.5000000000000000, 0.5000000000000000, 0.0000000000000000], 49 | [0.5000000000000000, 0.5000000000000000, 0.5000000000000000], 50 | [0.5000000000000000, 0.7500000000000000, 0.2500000000000000], 51 | [0.5000000000000000, 0.7500000000000000, 0.7500000000000000], 52 | [0.6250000000000000, 0.1250000000000000, 0.1250000000000000], 53 | [0.6250000000000000, 0.1250000000000000, 0.6250000000000000], 54 | [0.6250000000000000, 0.3750000000000000, 0.3750000000000000], 55 | [0.6250000000000000, 0.3750000000000000, 0.8750000000000000], 56 | [0.6250000000000000, 0.6250000000000000, 0.1250000000000000], 57 | [0.6250000000000000, 0.6250000000000000, 0.6250000000000000], 58 | [0.6250000000000000, 0.8750000000000000, 0.3750000000000000], 59 | [0.6250000000000000, 0.8750000000000000, 0.8750000000000000], 60 | [0.7500000000000000, 0.0000000000000000, 0.2500000000000000], 61 | [0.7500000000000000, 0.0000000000000000, 0.7500000000000000], 62 | [0.7500000000000000, 0.2500000000000000, 0.0000000000000000], 63 | [0.7500000000000000, 0.2500000000000000, 0.5000000000000000], 64 | [0.7500000000000000, 0.5000000000000000, 0.2500000000000000], 65 | [0.7500000000000000, 0.5000000000000000, 0.7500000000000000], 66 | [0.7500000000000000, 0.7500000000000000, 0.0000000000000000], 67 | [0.7500000000000000, 0.7500000000000000, 0.5000000000000000], 68 | [0.8750000000000000, 0.1250000000000000, 0.3750000000000000], 69 | [0.8750000000000000, 0.1250000000000000, 0.8750000000000000], 70 | [0.8750000000000000, 0.3750000000000000, 0.1250000000000000], 71 | [0.8750000000000000, 0.3750000000000000, 0.6250000000000000], 72 | [0.8750000000000000, 0.6250000000000000, 0.3750000000000000], 73 | [0.8750000000000000, 0.6250000000000000, 0.8750000000000000], 74 | [0.8750000000000000, 0.8750000000000000, 0.1250000000000000], 75 | [0.8750000000000000, 0.8750000000000000, 0.6250000000000000]] 76 | 77 | kd = [14] * 64 78 | 79 | force = np.loadtxt("force.dat").reshape((-1, 64, 3))[[0]] 80 | disp = np.loadtxt("disp.dat").reshape((-1, 64, 3))[[0]] 81 | 82 | # alm.alm_new() and alm.alm_delete() are done by 'with' statement 83 | with ALM(lavec, xcoord, kd) as alm: 84 | alm.define(1) 85 | alm.displacements = disp 86 | alm.forces = force 87 | info = alm.optimize() 88 | fc_values, elem_indices = alm.get_fc(1, mode='all') 89 | c = "xyz" 90 | for (fc, elem) in zip(fc_values, elem_indices): 91 | v1 = elem[0] // 3 92 | c1 = elem[0] % 3 93 | v2 = elem[1] // 3 94 | c2 = elem[1] % 3 95 | print("%f %d%s %d%s" % ((fc, v1 + 1, c[c1], v2 + 1, c[c2]))) 96 | 97 | alm.save_fc('alamode_fc.xml', format='alamode') 98 | -------------------------------------------------------------------------------- /example/Si_fitting2.py: -------------------------------------------------------------------------------- 1 | # 2 | # Si_fitting2.py 3 | # 4 | # This is an example to run ALM in the fitting mode. 5 | # 6 | 7 | from alm import ALM 8 | import numpy as np 9 | 10 | lavec = [[20.406, 0, 0], 11 | [0, 20.406, 0], 12 | [0, 0, 20.406]] 13 | xcoord = [[0.0000000000000000, 0.0000000000000000, 0.0000000000000000], 14 | [0.0000000000000000, 0.0000000000000000, 0.5000000000000000], 15 | [0.0000000000000000, 0.2500000000000000, 0.2500000000000000], 16 | [0.0000000000000000, 0.2500000000000000, 0.7500000000000000], 17 | [0.0000000000000000, 0.5000000000000000, 0.0000000000000000], 18 | [0.0000000000000000, 0.5000000000000000, 0.5000000000000000], 19 | [0.0000000000000000, 0.7500000000000000, 0.2500000000000000], 20 | [0.0000000000000000, 0.7500000000000000, 0.7500000000000000], 21 | [0.1250000000000000, 0.1250000000000000, 0.1250000000000000], 22 | [0.1250000000000000, 0.1250000000000000, 0.6250000000000000], 23 | [0.1250000000000000, 0.3750000000000000, 0.3750000000000000], 24 | [0.1250000000000000, 0.3750000000000000, 0.8750000000000000], 25 | [0.1250000000000000, 0.6250000000000000, 0.1250000000000000], 26 | [0.1250000000000000, 0.6250000000000000, 0.6250000000000000], 27 | [0.1250000000000000, 0.8750000000000000, 0.3750000000000000], 28 | [0.1250000000000000, 0.8750000000000000, 0.8750000000000000], 29 | [0.2500000000000000, 0.0000000000000000, 0.2500000000000000], 30 | [0.2500000000000000, 0.0000000000000000, 0.7500000000000000], 31 | [0.2500000000000000, 0.2500000000000000, 0.0000000000000000], 32 | [0.2500000000000000, 0.2500000000000000, 0.5000000000000000], 33 | [0.2500000000000000, 0.5000000000000000, 0.2500000000000000], 34 | [0.2500000000000000, 0.5000000000000000, 0.7500000000000000], 35 | [0.2500000000000000, 0.7500000000000000, 0.0000000000000000], 36 | [0.2500000000000000, 0.7500000000000000, 0.5000000000000000], 37 | [0.3750000000000000, 0.1250000000000000, 0.3750000000000000], 38 | [0.3750000000000000, 0.1250000000000000, 0.8750000000000000], 39 | [0.3750000000000000, 0.3750000000000000, 0.1250000000000000], 40 | [0.3750000000000000, 0.3750000000000000, 0.6250000000000000], 41 | [0.3750000000000000, 0.6250000000000000, 0.3750000000000000], 42 | [0.3750000000000000, 0.6250000000000000, 0.8750000000000000], 43 | [0.3750000000000000, 0.8750000000000000, 0.1250000000000000], 44 | [0.3750000000000000, 0.8750000000000000, 0.6250000000000000], 45 | [0.5000000000000000, 0.0000000000000000, 0.0000000000000000], 46 | [0.5000000000000000, 0.0000000000000000, 0.5000000000000000], 47 | [0.5000000000000000, 0.2500000000000000, 0.2500000000000000], 48 | [0.5000000000000000, 0.2500000000000000, 0.7500000000000000], 49 | [0.5000000000000000, 0.5000000000000000, 0.0000000000000000], 50 | [0.5000000000000000, 0.5000000000000000, 0.5000000000000000], 51 | [0.5000000000000000, 0.7500000000000000, 0.2500000000000000], 52 | [0.5000000000000000, 0.7500000000000000, 0.7500000000000000], 53 | [0.6250000000000000, 0.1250000000000000, 0.1250000000000000], 54 | [0.6250000000000000, 0.1250000000000000, 0.6250000000000000], 55 | [0.6250000000000000, 0.3750000000000000, 0.3750000000000000], 56 | [0.6250000000000000, 0.3750000000000000, 0.8750000000000000], 57 | [0.6250000000000000, 0.6250000000000000, 0.1250000000000000], 58 | [0.6250000000000000, 0.6250000000000000, 0.6250000000000000], 59 | [0.6250000000000000, 0.8750000000000000, 0.3750000000000000], 60 | [0.6250000000000000, 0.8750000000000000, 0.8750000000000000], 61 | [0.7500000000000000, 0.0000000000000000, 0.2500000000000000], 62 | [0.7500000000000000, 0.0000000000000000, 0.7500000000000000], 63 | [0.7500000000000000, 0.2500000000000000, 0.0000000000000000], 64 | [0.7500000000000000, 0.2500000000000000, 0.5000000000000000], 65 | [0.7500000000000000, 0.5000000000000000, 0.2500000000000000], 66 | [0.7500000000000000, 0.5000000000000000, 0.7500000000000000], 67 | [0.7500000000000000, 0.7500000000000000, 0.0000000000000000], 68 | [0.7500000000000000, 0.7500000000000000, 0.5000000000000000], 69 | [0.8750000000000000, 0.1250000000000000, 0.3750000000000000], 70 | [0.8750000000000000, 0.1250000000000000, 0.8750000000000000], 71 | [0.8750000000000000, 0.3750000000000000, 0.1250000000000000], 72 | [0.8750000000000000, 0.3750000000000000, 0.6250000000000000], 73 | [0.8750000000000000, 0.6250000000000000, 0.3750000000000000], 74 | [0.8750000000000000, 0.6250000000000000, 0.8750000000000000], 75 | [0.8750000000000000, 0.8750000000000000, 0.1250000000000000], 76 | [0.8750000000000000, 0.8750000000000000, 0.6250000000000000]] 77 | 78 | kd = [14] * 64 79 | 80 | force = np.loadtxt("force.dat").reshape((-1, 64, 3))[:22] 81 | disp = np.loadtxt("disp.dat").reshape((-1, 64, 3))[:22] 82 | 83 | # alm.alm_new() and alm.alm_delete() are done by 'with' statement 84 | with ALM(lavec, xcoord, kd) as alm: 85 | alm.define(2, [-1, 7.3]) 86 | alm.displacements = disp 87 | alm.forces = force 88 | info = alm.optimize() 89 | 90 | c = "xyz" 91 | fc_values, elem_indices = alm.get_fc(1) # harmonic fc 92 | for (fc, elem) in zip(fc_values, elem_indices): 93 | v1 = elem[0] // 3 94 | c1 = elem[0] % 3 95 | v2 = elem[1] // 3 96 | c2 = elem[1] % 3 97 | print("%f %d%s %d%s" % ((fc, v1 + 1, c[c1], v2 + 1, c[c2]))) 98 | 99 | fc_values, elem_indices = alm.get_fc(2) # cubic fc 100 | for (fc, elem) in zip(fc_values, elem_indices): 101 | v1 = elem[0] // 3 102 | c1 = elem[0] % 3 103 | v2 = elem[1] // 3 104 | c2 = elem[1] % 3 105 | v3 = elem[2] // 3 106 | c3 = elem[2] % 3 107 | print("%f %d%s %d%s %d%s" % ((fc, 108 | v1 + 1, c[c1], 109 | v2 + 1, c[c2], 110 | v3 + 1, c[c3]))) 111 | 112 | alm.save_fc('FORCE_CONSTANT_3RD', format='shengbte') 113 | 114 | -------------------------------------------------------------------------------- /example/Si_fitting_external.py: -------------------------------------------------------------------------------- 1 | # 2 | # Si_fitting_external.py 3 | # 4 | # This is an example to run ALM in the fitting mode. 5 | # Compare internal optimizer and the numpy routine for fitting 6 | # 7 | 8 | from alm import ALM 9 | import numpy as np 10 | 11 | lavec = [[20.406, 0, 0], 12 | [0, 20.406, 0], 13 | [0, 0, 20.406]] 14 | xcoord = [[0.0000000000000000, 0.0000000000000000, 0.0000000000000000], 15 | [0.0000000000000000, 0.0000000000000000, 0.5000000000000000], 16 | [0.0000000000000000, 0.2500000000000000, 0.2500000000000000], 17 | [0.0000000000000000, 0.2500000000000000, 0.7500000000000000], 18 | [0.0000000000000000, 0.5000000000000000, 0.0000000000000000], 19 | [0.0000000000000000, 0.5000000000000000, 0.5000000000000000], 20 | [0.0000000000000000, 0.7500000000000000, 0.2500000000000000], 21 | [0.0000000000000000, 0.7500000000000000, 0.7500000000000000], 22 | [0.1250000000000000, 0.1250000000000000, 0.1250000000000000], 23 | [0.1250000000000000, 0.1250000000000000, 0.6250000000000000], 24 | [0.1250000000000000, 0.3750000000000000, 0.3750000000000000], 25 | [0.1250000000000000, 0.3750000000000000, 0.8750000000000000], 26 | [0.1250000000000000, 0.6250000000000000, 0.1250000000000000], 27 | [0.1250000000000000, 0.6250000000000000, 0.6250000000000000], 28 | [0.1250000000000000, 0.8750000000000000, 0.3750000000000000], 29 | [0.1250000000000000, 0.8750000000000000, 0.8750000000000000], 30 | [0.2500000000000000, 0.0000000000000000, 0.2500000000000000], 31 | [0.2500000000000000, 0.0000000000000000, 0.7500000000000000], 32 | [0.2500000000000000, 0.2500000000000000, 0.0000000000000000], 33 | [0.2500000000000000, 0.2500000000000000, 0.5000000000000000], 34 | [0.2500000000000000, 0.5000000000000000, 0.2500000000000000], 35 | [0.2500000000000000, 0.5000000000000000, 0.7500000000000000], 36 | [0.2500000000000000, 0.7500000000000000, 0.0000000000000000], 37 | [0.2500000000000000, 0.7500000000000000, 0.5000000000000000], 38 | [0.3750000000000000, 0.1250000000000000, 0.3750000000000000], 39 | [0.3750000000000000, 0.1250000000000000, 0.8750000000000000], 40 | [0.3750000000000000, 0.3750000000000000, 0.1250000000000000], 41 | [0.3750000000000000, 0.3750000000000000, 0.6250000000000000], 42 | [0.3750000000000000, 0.6250000000000000, 0.3750000000000000], 43 | [0.3750000000000000, 0.6250000000000000, 0.8750000000000000], 44 | [0.3750000000000000, 0.8750000000000000, 0.1250000000000000], 45 | [0.3750000000000000, 0.8750000000000000, 0.6250000000000000], 46 | [0.5000000000000000, 0.0000000000000000, 0.0000000000000000], 47 | [0.5000000000000000, 0.0000000000000000, 0.5000000000000000], 48 | [0.5000000000000000, 0.2500000000000000, 0.2500000000000000], 49 | [0.5000000000000000, 0.2500000000000000, 0.7500000000000000], 50 | [0.5000000000000000, 0.5000000000000000, 0.0000000000000000], 51 | [0.5000000000000000, 0.5000000000000000, 0.5000000000000000], 52 | [0.5000000000000000, 0.7500000000000000, 0.2500000000000000], 53 | [0.5000000000000000, 0.7500000000000000, 0.7500000000000000], 54 | [0.6250000000000000, 0.1250000000000000, 0.1250000000000000], 55 | [0.6250000000000000, 0.1250000000000000, 0.6250000000000000], 56 | [0.6250000000000000, 0.3750000000000000, 0.3750000000000000], 57 | [0.6250000000000000, 0.3750000000000000, 0.8750000000000000], 58 | [0.6250000000000000, 0.6250000000000000, 0.1250000000000000], 59 | [0.6250000000000000, 0.6250000000000000, 0.6250000000000000], 60 | [0.6250000000000000, 0.8750000000000000, 0.3750000000000000], 61 | [0.6250000000000000, 0.8750000000000000, 0.8750000000000000], 62 | [0.7500000000000000, 0.0000000000000000, 0.2500000000000000], 63 | [0.7500000000000000, 0.0000000000000000, 0.7500000000000000], 64 | [0.7500000000000000, 0.2500000000000000, 0.0000000000000000], 65 | [0.7500000000000000, 0.2500000000000000, 0.5000000000000000], 66 | [0.7500000000000000, 0.5000000000000000, 0.2500000000000000], 67 | [0.7500000000000000, 0.5000000000000000, 0.7500000000000000], 68 | [0.7500000000000000, 0.7500000000000000, 0.0000000000000000], 69 | [0.7500000000000000, 0.7500000000000000, 0.5000000000000000], 70 | [0.8750000000000000, 0.1250000000000000, 0.3750000000000000], 71 | [0.8750000000000000, 0.1250000000000000, 0.8750000000000000], 72 | [0.8750000000000000, 0.3750000000000000, 0.1250000000000000], 73 | [0.8750000000000000, 0.3750000000000000, 0.6250000000000000], 74 | [0.8750000000000000, 0.6250000000000000, 0.3750000000000000], 75 | [0.8750000000000000, 0.6250000000000000, 0.8750000000000000], 76 | [0.8750000000000000, 0.8750000000000000, 0.1250000000000000], 77 | [0.8750000000000000, 0.8750000000000000, 0.6250000000000000]] 78 | 79 | kd = [14] * 64 80 | 81 | force = np.loadtxt("force.dat").reshape((-1, 64, 3))[:22] 82 | disp = np.loadtxt("disp.dat").reshape((-1, 64, 3))[:22] 83 | 84 | # Initialize object 85 | with ALM(lavec, xcoord, kd) as alm: 86 | # Set displacement and force data 87 | alm.displacements = disp 88 | alm.forces = force 89 | 90 | # Define the taylor expansion model and find force constants 91 | alm.define(2, [[[-1]], [[7.3]]]) 92 | 93 | # Set up options for translational invariance 94 | alm.set_constraint(translation=True) 95 | 96 | # 97 | # Run fitting by internal function 98 | # 99 | alm.optimize() 100 | fc_values1, elem_indices1 = alm.get_fc(2) 101 | 102 | # 103 | # Run fitting by numpy function 104 | # 105 | # First, get matrix elements for fitting 106 | amat, bvec = alm.get_matrix_elements() 107 | # Perform fitting 108 | fc = np.linalg.lstsq(amat, bvec, rcond=1.0e-15) 109 | # Copy the solution values to alm object 110 | # This is necessary to use get_fc function 111 | alm.set_fc(fc[0]) 112 | fc_values2, elem_indices2 = alm.get_fc(2) 113 | 114 | c = "xyz" 115 | 116 | diffs = [] 117 | for (fc, fc_ext, elem) in zip(fc_values1, fc_values2, elem_indices2): 118 | v1 = elem[0] // 3 119 | c1 = elem[0] % 3 120 | v2 = elem[1] // 3 121 | c2 = elem[1] % 3 122 | v3 = elem[2] // 3 123 | c3 = elem[2] % 3 124 | diffs.append(fc - fc_ext) 125 | print("%15.7f %15.7f %15.6e %d%s %d%s %d%s" 126 | % ((fc, fc_ext, fc - fc_ext, 127 | v1 + 1, c[c1], v2 + 1, c[c2], v3 + 1, c[c3]))) 128 | 129 | print("") 130 | print("* Largest difference between internal and external: %e" 131 | % np.max(np.abs(diffs))) 132 | -------------------------------------------------------------------------------- /example/Si_fitting_insteps.py: -------------------------------------------------------------------------------- 1 | # 2 | # Si_fitting_insteps.py 3 | # 4 | # This is an example to run ALM for fitting FC2->FC3 in steps, 5 | # where the FC2 values are fixed in the second step by using 6 | # fc_freeze method. 7 | 8 | from alm import ALM 9 | import numpy as np 10 | 11 | lavec = [[20.406, 0, 0], 12 | [0, 20.406, 0], 13 | [0, 0, 20.406]] 14 | xcoord = [[0.0000000000000000, 0.0000000000000000, 0.0000000000000000], 15 | [0.0000000000000000, 0.0000000000000000, 0.5000000000000000], 16 | [0.0000000000000000, 0.2500000000000000, 0.2500000000000000], 17 | [0.0000000000000000, 0.2500000000000000, 0.7500000000000000], 18 | [0.0000000000000000, 0.5000000000000000, 0.0000000000000000], 19 | [0.0000000000000000, 0.5000000000000000, 0.5000000000000000], 20 | [0.0000000000000000, 0.7500000000000000, 0.2500000000000000], 21 | [0.0000000000000000, 0.7500000000000000, 0.7500000000000000], 22 | [0.1250000000000000, 0.1250000000000000, 0.1250000000000000], 23 | [0.1250000000000000, 0.1250000000000000, 0.6250000000000000], 24 | [0.1250000000000000, 0.3750000000000000, 0.3750000000000000], 25 | [0.1250000000000000, 0.3750000000000000, 0.8750000000000000], 26 | [0.1250000000000000, 0.6250000000000000, 0.1250000000000000], 27 | [0.1250000000000000, 0.6250000000000000, 0.6250000000000000], 28 | [0.1250000000000000, 0.8750000000000000, 0.3750000000000000], 29 | [0.1250000000000000, 0.8750000000000000, 0.8750000000000000], 30 | [0.2500000000000000, 0.0000000000000000, 0.2500000000000000], 31 | [0.2500000000000000, 0.0000000000000000, 0.7500000000000000], 32 | [0.2500000000000000, 0.2500000000000000, 0.0000000000000000], 33 | [0.2500000000000000, 0.2500000000000000, 0.5000000000000000], 34 | [0.2500000000000000, 0.5000000000000000, 0.2500000000000000], 35 | [0.2500000000000000, 0.5000000000000000, 0.7500000000000000], 36 | [0.2500000000000000, 0.7500000000000000, 0.0000000000000000], 37 | [0.2500000000000000, 0.7500000000000000, 0.5000000000000000], 38 | [0.3750000000000000, 0.1250000000000000, 0.3750000000000000], 39 | [0.3750000000000000, 0.1250000000000000, 0.8750000000000000], 40 | [0.3750000000000000, 0.3750000000000000, 0.1250000000000000], 41 | [0.3750000000000000, 0.3750000000000000, 0.6250000000000000], 42 | [0.3750000000000000, 0.6250000000000000, 0.3750000000000000], 43 | [0.3750000000000000, 0.6250000000000000, 0.8750000000000000], 44 | [0.3750000000000000, 0.8750000000000000, 0.1250000000000000], 45 | [0.3750000000000000, 0.8750000000000000, 0.6250000000000000], 46 | [0.5000000000000000, 0.0000000000000000, 0.0000000000000000], 47 | [0.5000000000000000, 0.0000000000000000, 0.5000000000000000], 48 | [0.5000000000000000, 0.2500000000000000, 0.2500000000000000], 49 | [0.5000000000000000, 0.2500000000000000, 0.7500000000000000], 50 | [0.5000000000000000, 0.5000000000000000, 0.0000000000000000], 51 | [0.5000000000000000, 0.5000000000000000, 0.5000000000000000], 52 | [0.5000000000000000, 0.7500000000000000, 0.2500000000000000], 53 | [0.5000000000000000, 0.7500000000000000, 0.7500000000000000], 54 | [0.6250000000000000, 0.1250000000000000, 0.1250000000000000], 55 | [0.6250000000000000, 0.1250000000000000, 0.6250000000000000], 56 | [0.6250000000000000, 0.3750000000000000, 0.3750000000000000], 57 | [0.6250000000000000, 0.3750000000000000, 0.8750000000000000], 58 | [0.6250000000000000, 0.6250000000000000, 0.1250000000000000], 59 | [0.6250000000000000, 0.6250000000000000, 0.6250000000000000], 60 | [0.6250000000000000, 0.8750000000000000, 0.3750000000000000], 61 | [0.6250000000000000, 0.8750000000000000, 0.8750000000000000], 62 | [0.7500000000000000, 0.0000000000000000, 0.2500000000000000], 63 | [0.7500000000000000, 0.0000000000000000, 0.7500000000000000], 64 | [0.7500000000000000, 0.2500000000000000, 0.0000000000000000], 65 | [0.7500000000000000, 0.2500000000000000, 0.5000000000000000], 66 | [0.7500000000000000, 0.5000000000000000, 0.2500000000000000], 67 | [0.7500000000000000, 0.5000000000000000, 0.7500000000000000], 68 | [0.7500000000000000, 0.7500000000000000, 0.0000000000000000], 69 | [0.7500000000000000, 0.7500000000000000, 0.5000000000000000], 70 | [0.8750000000000000, 0.1250000000000000, 0.3750000000000000], 71 | [0.8750000000000000, 0.1250000000000000, 0.8750000000000000], 72 | [0.8750000000000000, 0.3750000000000000, 0.1250000000000000], 73 | [0.8750000000000000, 0.3750000000000000, 0.6250000000000000], 74 | [0.8750000000000000, 0.6250000000000000, 0.3750000000000000], 75 | [0.8750000000000000, 0.6250000000000000, 0.8750000000000000], 76 | [0.8750000000000000, 0.8750000000000000, 0.1250000000000000], 77 | [0.8750000000000000, 0.8750000000000000, 0.6250000000000000]] 78 | 79 | kd = [14] * 64 80 | 81 | force = np.loadtxt("force.dat").reshape((-1, 64, 3))[[0]] 82 | disp = np.loadtxt("disp.dat").reshape((-1, 64, 3))[[0]] 83 | 84 | force3 = np.loadtxt("force.dat").reshape((-1, 64, 3))[1:22] 85 | disp3 = np.loadtxt("disp.dat").reshape((-1, 64, 3))[1:22] 86 | 87 | # alm.alm_new() and alm.alm_delete() are done by 'with' statement 88 | with ALM(lavec, xcoord, kd) as alm: 89 | alm.set_verbosity(0) 90 | 91 | # Harmonic model 92 | alm.define(1, [-1], symmetrization_basis="Cartesian") 93 | alm.displacements = disp 94 | alm.forces = force 95 | info = alm.optimize() 96 | fc2_values, elem2_indices = alm.get_fc(1) # harmonic fc 97 | alm.save_fc('harmonic.xml', format='alamode') 98 | 99 | # Third-order model 100 | alm.define(2, [-1, 7.6], symmetrization_basis="Cartesian") 101 | alm.displacements = disp3 102 | alm.forces = force3 103 | #alm.set_constraint(translation=True, rotation=False) 104 | 105 | # Fix FC2 to the previously calculated values 106 | alm.freeze_fc(fc2_values, elem2_indices) 107 | 108 | info = alm.optimize() 109 | fc3_values, elem3_indices = alm.get_fc(2) 110 | alm.save_fc('anharmonic2.xml', format='alamode') 111 | 112 | #alm.freeze_fc(fc3_values, elem3_indices) 113 | #info = alm.optimize() 114 | #alm.save_fc('anharmonic2_rep.xml', format='alamode') 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /example/Si_suggest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | suggest_Si.cpp 3 | 4 | This is an example to run ALM in the suggest mode. 5 | 6 | */ 7 | 8 | #include "alm.h" 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | ALM_NS::ALM *alm = new ALM_NS::ALM(); 15 | 16 | double lavec[3][3] = {{20.406, 0, 0}, 17 | {0, 20.406, 0}, 18 | {0, 0, 20.406}}; 19 | double xcoord[][3] = 20 | {{ 0.0000000000000000, 0.0000000000000000, 0.0000000000000000}, 21 | { 0.0000000000000000, 0.0000000000000000, 0.5000000000000000}, 22 | { 0.0000000000000000, 0.2500000000000000, 0.2500000000000000}, 23 | { 0.0000000000000000, 0.2500000000000000, 0.7500000000000000}, 24 | { 0.0000000000000000, 0.5000000000000000, 0.0000000000000000}, 25 | { 0.0000000000000000, 0.5000000000000000, 0.5000000000000000}, 26 | { 0.0000000000000000, 0.7500000000000000, 0.2500000000000000}, 27 | { 0.0000000000000000, 0.7500000000000000, 0.7500000000000000}, 28 | { 0.1250000000000000, 0.1250000000000000, 0.1250000000000000}, 29 | { 0.1250000000000000, 0.1250000000000000, 0.6250000000000000}, 30 | { 0.1250000000000000, 0.3750000000000000, 0.3750000000000000}, 31 | { 0.1250000000000000, 0.3750000000000000, 0.8750000000000000}, 32 | { 0.1250000000000000, 0.6250000000000000, 0.1250000000000000}, 33 | { 0.1250000000000000, 0.6250000000000000, 0.6250000000000000}, 34 | { 0.1250000000000000, 0.8750000000000000, 0.3750000000000000}, 35 | { 0.1250000000000000, 0.8750000000000000, 0.8750000000000000}, 36 | { 0.2500000000000000, 0.0000000000000000, 0.2500000000000000}, 37 | { 0.2500000000000000, 0.0000000000000000, 0.7500000000000000}, 38 | { 0.2500000000000000, 0.2500000000000000, 0.0000000000000000}, 39 | { 0.2500000000000000, 0.2500000000000000, 0.5000000000000000}, 40 | { 0.2500000000000000, 0.5000000000000000, 0.2500000000000000}, 41 | { 0.2500000000000000, 0.5000000000000000, 0.7500000000000000}, 42 | { 0.2500000000000000, 0.7500000000000000, 0.0000000000000000}, 43 | { 0.2500000000000000, 0.7500000000000000, 0.5000000000000000}, 44 | { 0.3750000000000000, 0.1250000000000000, 0.3750000000000000}, 45 | { 0.3750000000000000, 0.1250000000000000, 0.8750000000000000}, 46 | { 0.3750000000000000, 0.3750000000000000, 0.1250000000000000}, 47 | { 0.3750000000000000, 0.3750000000000000, 0.6250000000000000}, 48 | { 0.3750000000000000, 0.6250000000000000, 0.3750000000000000}, 49 | { 0.3750000000000000, 0.6250000000000000, 0.8750000000000000}, 50 | { 0.3750000000000000, 0.8750000000000000, 0.1250000000000000}, 51 | { 0.3750000000000000, 0.8750000000000000, 0.6250000000000000}, 52 | { 0.5000000000000000, 0.0000000000000000, 0.0000000000000000}, 53 | { 0.5000000000000000, 0.0000000000000000, 0.5000000000000000}, 54 | { 0.5000000000000000, 0.2500000000000000, 0.2500000000000000}, 55 | { 0.5000000000000000, 0.2500000000000000, 0.7500000000000000}, 56 | { 0.5000000000000000, 0.5000000000000000, 0.0000000000000000}, 57 | { 0.5000000000000000, 0.5000000000000000, 0.5000000000000000}, 58 | { 0.5000000000000000, 0.7500000000000000, 0.2500000000000000}, 59 | { 0.5000000000000000, 0.7500000000000000, 0.7500000000000000}, 60 | { 0.6250000000000000, 0.1250000000000000, 0.1250000000000000}, 61 | { 0.6250000000000000, 0.1250000000000000, 0.6250000000000000}, 62 | { 0.6250000000000000, 0.3750000000000000, 0.3750000000000000}, 63 | { 0.6250000000000000, 0.3750000000000000, 0.8750000000000000}, 64 | { 0.6250000000000000, 0.6250000000000000, 0.1250000000000000}, 65 | { 0.6250000000000000, 0.6250000000000000, 0.6250000000000000}, 66 | { 0.6250000000000000, 0.8750000000000000, 0.3750000000000000}, 67 | { 0.6250000000000000, 0.8750000000000000, 0.8750000000000000}, 68 | { 0.7500000000000000, 0.0000000000000000, 0.2500000000000000}, 69 | { 0.7500000000000000, 0.0000000000000000, 0.7500000000000000}, 70 | { 0.7500000000000000, 0.2500000000000000, 0.0000000000000000}, 71 | { 0.7500000000000000, 0.2500000000000000, 0.5000000000000000}, 72 | { 0.7500000000000000, 0.5000000000000000, 0.2500000000000000}, 73 | { 0.7500000000000000, 0.5000000000000000, 0.7500000000000000}, 74 | { 0.7500000000000000, 0.7500000000000000, 0.0000000000000000}, 75 | { 0.7500000000000000, 0.7500000000000000, 0.5000000000000000}, 76 | { 0.8750000000000000, 0.1250000000000000, 0.3750000000000000}, 77 | { 0.8750000000000000, 0.1250000000000000, 0.8750000000000000}, 78 | { 0.8750000000000000, 0.3750000000000000, 0.1250000000000000}, 79 | { 0.8750000000000000, 0.3750000000000000, 0.6250000000000000}, 80 | { 0.8750000000000000, 0.6250000000000000, 0.3750000000000000}, 81 | { 0.8750000000000000, 0.6250000000000000, 0.8750000000000000}, 82 | { 0.8750000000000000, 0.8750000000000000, 0.1250000000000000}, 83 | { 0.8750000000000000, 0.8750000000000000, 0.6250000000000000}}; 84 | const int nat = 64; 85 | const int nkd = 1; 86 | int kd[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 87 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 88 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 89 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 90 | std::string kdname[] = {"Si"}; 91 | 92 | int nbody_include[1] = {2}; 93 | double cutoff_radii[1] = {-1.0}; 94 | 95 | const int fc_order = 1; 96 | alm->set_verbosity(0); 97 | alm->set_run_mode("suggest"); 98 | alm->set_output_filename_prefix("si222API"); 99 | alm->set_cell(64, lavec, xcoord, kd, kdname); 100 | //alm->set_norder(fc_order); 101 | alm->define(fc_order, nkd, nbody_include, cutoff_radii); 102 | //int nbody_include[fc_order] = {2}; 103 | //alm->set_interaction_range(nbody_include); 104 | alm->run(); 105 | 106 | std::cout << "************ ALM API ************" << std::endl; 107 | std::cout << "Atom mapping from primitive to supercell:" << std::endl; 108 | //int map_p2s[nat]; 109 | auto map_p2s = alm->get_atom_mapping_by_pure_translations(); 110 | auto num_trans = map_p2s[0].size(); 111 | std::cout << "Number of translations: " << num_trans << std::endl; 112 | for (int i = 0; i < num_trans; ++i) { 113 | std::cout << i + 1 << " [ "; 114 | for (int j = 0; j < nat / num_trans; ++j) { 115 | std::cout << map_p2s[j][i] + 1 << " "; 116 | } 117 | std::cout << "]" << std::endl; 118 | } 119 | std::cout << std::endl; 120 | 121 | std::cout << "Displacement patterns:" << std::endl; 122 | const int num_patterns = alm->get_number_of_displacement_patterns(fc_order); 123 | int numbers[num_patterns]; 124 | alm->get_number_of_displaced_atoms(numbers, fc_order); 125 | int total_num_disps = 0; 126 | for (int i = 0; i < num_patterns; i++) { 127 | total_num_disps += numbers[i]; 128 | } 129 | int atom_indices[total_num_disps]; 130 | double disp_patterns[total_num_disps * 3]; 131 | const int basis = alm->get_displacement_patterns(atom_indices, 132 | disp_patterns, 133 | fc_order); 134 | 135 | const std::string str_basis[2] = {"Cartesian", "Fractional"}; 136 | std::cout << "Basis: " << str_basis[basis] << std::endl; 137 | int i_atom = 0; 138 | int i_disp = 0; 139 | for (int i = 0; i < num_patterns; i++) { 140 | std::cout << i + 1 << " : " << numbers[i] << std::endl; 141 | for (int j = 0; j < numbers[i]; j++) { 142 | std::cout << " " << atom_indices[i_atom] + 1 << " : "; 143 | ++i_atom; 144 | std::cout << disp_patterns[i_disp] << " "; ++i_disp; 145 | std::cout << disp_patterns[i_disp] << " "; ++i_disp; 146 | std::cout << disp_patterns[i_disp] << std::endl; ++i_disp; 147 | } 148 | } 149 | std::cout << "************ ALM API ************" << std::endl; 150 | 151 | delete alm; 152 | 153 | return 1; 154 | } 155 | -------------------------------------------------------------------------------- /example/Si_suggest.py: -------------------------------------------------------------------------------- 1 | # 2 | # Si_suggest.py 3 | # 4 | # This is an example to run ALM in the suggest mode. 5 | # 6 | 7 | from alm import ALM 8 | 9 | lavec = [[20.406, 0, 0], 10 | [0, 20.406, 0], 11 | [0, 0, 20.406]] 12 | xcoord = [[0.0000000000000000, 0.0000000000000000, 0.0000000000000000], 13 | [0.0000000000000000, 0.0000000000000000, 0.5000000000000000], 14 | [0.0000000000000000, 0.2500000000000000, 0.2500000000000000], 15 | [0.0000000000000000, 0.2500000000000000, 0.7500000000000000], 16 | [0.0000000000000000, 0.5000000000000000, 0.0000000000000000], 17 | [0.0000000000000000, 0.5000000000000000, 0.5000000000000000], 18 | [0.0000000000000000, 0.7500000000000000, 0.2500000000000000], 19 | [0.0000000000000000, 0.7500000000000000, 0.7500000000000000], 20 | [0.1250000000000000, 0.1250000000000000, 0.1250000000000000], 21 | [0.1250000000000000, 0.1250000000000000, 0.6250000000000000], 22 | [0.1250000000000000, 0.3750000000000000, 0.3750000000000000], 23 | [0.1250000000000000, 0.3750000000000000, 0.8750000000000000], 24 | [0.1250000000000000, 0.6250000000000000, 0.1250000000000000], 25 | [0.1250000000000000, 0.6250000000000000, 0.6250000000000000], 26 | [0.1250000000000000, 0.8750000000000000, 0.3750000000000000], 27 | [0.1250000000000000, 0.8750000000000000, 0.8750000000000000], 28 | [0.2500000000000000, 0.0000000000000000, 0.2500000000000000], 29 | [0.2500000000000000, 0.0000000000000000, 0.7500000000000000], 30 | [0.2500000000000000, 0.2500000000000000, 0.0000000000000000], 31 | [0.2500000000000000, 0.2500000000000000, 0.5000000000000000], 32 | [0.2500000000000000, 0.5000000000000000, 0.2500000000000000], 33 | [0.2500000000000000, 0.5000000000000000, 0.7500000000000000], 34 | [0.2500000000000000, 0.7500000000000000, 0.0000000000000000], 35 | [0.2500000000000000, 0.7500000000000000, 0.5000000000000000], 36 | [0.3750000000000000, 0.1250000000000000, 0.3750000000000000], 37 | [0.3750000000000000, 0.1250000000000000, 0.8750000000000000], 38 | [0.3750000000000000, 0.3750000000000000, 0.1250000000000000], 39 | [0.3750000000000000, 0.3750000000000000, 0.6250000000000000], 40 | [0.3750000000000000, 0.6250000000000000, 0.3750000000000000], 41 | [0.3750000000000000, 0.6250000000000000, 0.8750000000000000], 42 | [0.3750000000000000, 0.8750000000000000, 0.1250000000000000], 43 | [0.3750000000000000, 0.8750000000000000, 0.6250000000000000], 44 | [0.5000000000000000, 0.0000000000000000, 0.0000000000000000], 45 | [0.5000000000000000, 0.0000000000000000, 0.5000000000000000], 46 | [0.5000000000000000, 0.2500000000000000, 0.2500000000000000], 47 | [0.5000000000000000, 0.2500000000000000, 0.7500000000000000], 48 | [0.5000000000000000, 0.5000000000000000, 0.0000000000000000], 49 | [0.5000000000000000, 0.5000000000000000, 0.5000000000000000], 50 | [0.5000000000000000, 0.7500000000000000, 0.2500000000000000], 51 | [0.5000000000000000, 0.7500000000000000, 0.7500000000000000], 52 | [0.6250000000000000, 0.1250000000000000, 0.1250000000000000], 53 | [0.6250000000000000, 0.1250000000000000, 0.6250000000000000], 54 | [0.6250000000000000, 0.3750000000000000, 0.3750000000000000], 55 | [0.6250000000000000, 0.3750000000000000, 0.8750000000000000], 56 | [0.6250000000000000, 0.6250000000000000, 0.1250000000000000], 57 | [0.6250000000000000, 0.6250000000000000, 0.6250000000000000], 58 | [0.6250000000000000, 0.8750000000000000, 0.3750000000000000], 59 | [0.6250000000000000, 0.8750000000000000, 0.8750000000000000], 60 | [0.7500000000000000, 0.0000000000000000, 0.2500000000000000], 61 | [0.7500000000000000, 0.0000000000000000, 0.7500000000000000], 62 | [0.7500000000000000, 0.2500000000000000, 0.0000000000000000], 63 | [0.7500000000000000, 0.2500000000000000, 0.5000000000000000], 64 | [0.7500000000000000, 0.5000000000000000, 0.2500000000000000], 65 | [0.7500000000000000, 0.5000000000000000, 0.7500000000000000], 66 | [0.7500000000000000, 0.7500000000000000, 0.0000000000000000], 67 | [0.7500000000000000, 0.7500000000000000, 0.5000000000000000], 68 | [0.8750000000000000, 0.1250000000000000, 0.3750000000000000], 69 | [0.8750000000000000, 0.1250000000000000, 0.8750000000000000], 70 | [0.8750000000000000, 0.3750000000000000, 0.1250000000000000], 71 | [0.8750000000000000, 0.3750000000000000, 0.6250000000000000], 72 | [0.8750000000000000, 0.6250000000000000, 0.3750000000000000], 73 | [0.8750000000000000, 0.6250000000000000, 0.8750000000000000], 74 | [0.8750000000000000, 0.8750000000000000, 0.1250000000000000], 75 | [0.8750000000000000, 0.8750000000000000, 0.6250000000000000]] 76 | 77 | kd = [14] * 64 78 | 79 | # alm.alm_new() and alm.alm_delete() are done by 'with' statement 80 | with ALM(lavec, xcoord, kd) as alm: 81 | alm.define(1) 82 | alm.suggest() 83 | print(alm.getmap_primitive_to_supercell()) 84 | print(alm.get_displacement_patterns(1)) 85 | -------------------------------------------------------------------------------- /example/Si_suggest2.py: -------------------------------------------------------------------------------- 1 | # 2 | # Si_suggest.py 3 | # 4 | # This is an example to run ALM in the suggest mode. 5 | # 6 | 7 | from alm import ALM 8 | 9 | lavec = [[20.406, 0, 0], 10 | [0, 20.406, 0], 11 | [0, 0, 20.406]] 12 | xcoord = [[0.0000000000000000, 0.0000000000000000, 0.0000000000000000], 13 | [0.0000000000000000, 0.0000000000000000, 0.5000000000000000], 14 | [0.0000000000000000, 0.2500000000000000, 0.2500000000000000], 15 | [0.0000000000000000, 0.2500000000000000, 0.7500000000000000], 16 | [0.0000000000000000, 0.5000000000000000, 0.0000000000000000], 17 | [0.0000000000000000, 0.5000000000000000, 0.5000000000000000], 18 | [0.0000000000000000, 0.7500000000000000, 0.2500000000000000], 19 | [0.0000000000000000, 0.7500000000000000, 0.7500000000000000], 20 | [0.1250000000000000, 0.1250000000000000, 0.1250000000000000], 21 | [0.1250000000000000, 0.1250000000000000, 0.6250000000000000], 22 | [0.1250000000000000, 0.3750000000000000, 0.3750000000000000], 23 | [0.1250000000000000, 0.3750000000000000, 0.8750000000000000], 24 | [0.1250000000000000, 0.6250000000000000, 0.1250000000000000], 25 | [0.1250000000000000, 0.6250000000000000, 0.6250000000000000], 26 | [0.1250000000000000, 0.8750000000000000, 0.3750000000000000], 27 | [0.1250000000000000, 0.8750000000000000, 0.8750000000000000], 28 | [0.2500000000000000, 0.0000000000000000, 0.2500000000000000], 29 | [0.2500000000000000, 0.0000000000000000, 0.7500000000000000], 30 | [0.2500000000000000, 0.2500000000000000, 0.0000000000000000], 31 | [0.2500000000000000, 0.2500000000000000, 0.5000000000000000], 32 | [0.2500000000000000, 0.5000000000000000, 0.2500000000000000], 33 | [0.2500000000000000, 0.5000000000000000, 0.7500000000000000], 34 | [0.2500000000000000, 0.7500000000000000, 0.0000000000000000], 35 | [0.2500000000000000, 0.7500000000000000, 0.5000000000000000], 36 | [0.3750000000000000, 0.1250000000000000, 0.3750000000000000], 37 | [0.3750000000000000, 0.1250000000000000, 0.8750000000000000], 38 | [0.3750000000000000, 0.3750000000000000, 0.1250000000000000], 39 | [0.3750000000000000, 0.3750000000000000, 0.6250000000000000], 40 | [0.3750000000000000, 0.6250000000000000, 0.3750000000000000], 41 | [0.3750000000000000, 0.6250000000000000, 0.8750000000000000], 42 | [0.3750000000000000, 0.8750000000000000, 0.1250000000000000], 43 | [0.3750000000000000, 0.8750000000000000, 0.6250000000000000], 44 | [0.5000000000000000, 0.0000000000000000, 0.0000000000000000], 45 | [0.5000000000000000, 0.0000000000000000, 0.5000000000000000], 46 | [0.5000000000000000, 0.2500000000000000, 0.2500000000000000], 47 | [0.5000000000000000, 0.2500000000000000, 0.7500000000000000], 48 | [0.5000000000000000, 0.5000000000000000, 0.0000000000000000], 49 | [0.5000000000000000, 0.5000000000000000, 0.5000000000000000], 50 | [0.5000000000000000, 0.7500000000000000, 0.2500000000000000], 51 | [0.5000000000000000, 0.7500000000000000, 0.7500000000000000], 52 | [0.6250000000000000, 0.1250000000000000, 0.1250000000000000], 53 | [0.6250000000000000, 0.1250000000000000, 0.6250000000000000], 54 | [0.6250000000000000, 0.3750000000000000, 0.3750000000000000], 55 | [0.6250000000000000, 0.3750000000000000, 0.8750000000000000], 56 | [0.6250000000000000, 0.6250000000000000, 0.1250000000000000], 57 | [0.6250000000000000, 0.6250000000000000, 0.6250000000000000], 58 | [0.6250000000000000, 0.8750000000000000, 0.3750000000000000], 59 | [0.6250000000000000, 0.8750000000000000, 0.8750000000000000], 60 | [0.7500000000000000, 0.0000000000000000, 0.2500000000000000], 61 | [0.7500000000000000, 0.0000000000000000, 0.7500000000000000], 62 | [0.7500000000000000, 0.2500000000000000, 0.0000000000000000], 63 | [0.7500000000000000, 0.2500000000000000, 0.5000000000000000], 64 | [0.7500000000000000, 0.5000000000000000, 0.2500000000000000], 65 | [0.7500000000000000, 0.5000000000000000, 0.7500000000000000], 66 | [0.7500000000000000, 0.7500000000000000, 0.0000000000000000], 67 | [0.7500000000000000, 0.7500000000000000, 0.5000000000000000], 68 | [0.8750000000000000, 0.1250000000000000, 0.3750000000000000], 69 | [0.8750000000000000, 0.1250000000000000, 0.8750000000000000], 70 | [0.8750000000000000, 0.3750000000000000, 0.1250000000000000], 71 | [0.8750000000000000, 0.3750000000000000, 0.6250000000000000], 72 | [0.8750000000000000, 0.6250000000000000, 0.3750000000000000], 73 | [0.8750000000000000, 0.6250000000000000, 0.8750000000000000], 74 | [0.8750000000000000, 0.8750000000000000, 0.1250000000000000], 75 | [0.8750000000000000, 0.8750000000000000, 0.6250000000000000]] 76 | 77 | kd = [14] * 64 78 | 79 | # alm.alm_new() and alm.alm_delete() are done by 'with' statement 80 | with ALM(lavec, xcoord, kd) as alm: 81 | alm.define(2, cutoff_radii=[[[-1]], [[7.3]]]) 82 | alm.suggest() 83 | print(alm.getmap_primitive_to_supercell()) 84 | for fc_order in (1, 2): 85 | print("fc_order: %d" % fc_order) 86 | for d in alm.get_displacement_patterns(fc_order): 87 | print(d) 88 | -------------------------------------------------------------------------------- /example/show_fc_dependency.py: -------------------------------------------------------------------------------- 1 | # 2 | # Si_fitting2.py 3 | # 4 | # This is an example to run ALM in the fitting mode. 5 | # 6 | 7 | from alm import ALM 8 | import numpy as np 9 | 10 | lavec = [[20.406, 0, 0], 11 | [0, 20.406, 0], 12 | [0, 0, 20.406]] 13 | xcoord = [[0.0000000000000000, 0.0000000000000000, 0.0000000000000000], 14 | [0.0000000000000000, 0.0000000000000000, 0.5000000000000000], 15 | [0.0000000000000000, 0.2500000000000000, 0.2500000000000000], 16 | [0.0000000000000000, 0.2500000000000000, 0.7500000000000000], 17 | [0.0000000000000000, 0.5000000000000000, 0.0000000000000000], 18 | [0.0000000000000000, 0.5000000000000000, 0.5000000000000000], 19 | [0.0000000000000000, 0.7500000000000000, 0.2500000000000000], 20 | [0.0000000000000000, 0.7500000000000000, 0.7500000000000000], 21 | [0.1250000000000000, 0.1250000000000000, 0.1250000000000000], 22 | [0.1250000000000000, 0.1250000000000000, 0.6250000000000000], 23 | [0.1250000000000000, 0.3750000000000000, 0.3750000000000000], 24 | [0.1250000000000000, 0.3750000000000000, 0.8750000000000000], 25 | [0.1250000000000000, 0.6250000000000000, 0.1250000000000000], 26 | [0.1250000000000000, 0.6250000000000000, 0.6250000000000000], 27 | [0.1250000000000000, 0.8750000000000000, 0.3750000000000000], 28 | [0.1250000000000000, 0.8750000000000000, 0.8750000000000000], 29 | [0.2500000000000000, 0.0000000000000000, 0.2500000000000000], 30 | [0.2500000000000000, 0.0000000000000000, 0.7500000000000000], 31 | [0.2500000000000000, 0.2500000000000000, 0.0000000000000000], 32 | [0.2500000000000000, 0.2500000000000000, 0.5000000000000000], 33 | [0.2500000000000000, 0.5000000000000000, 0.2500000000000000], 34 | [0.2500000000000000, 0.5000000000000000, 0.7500000000000000], 35 | [0.2500000000000000, 0.7500000000000000, 0.0000000000000000], 36 | [0.2500000000000000, 0.7500000000000000, 0.5000000000000000], 37 | [0.3750000000000000, 0.1250000000000000, 0.3750000000000000], 38 | [0.3750000000000000, 0.1250000000000000, 0.8750000000000000], 39 | [0.3750000000000000, 0.3750000000000000, 0.1250000000000000], 40 | [0.3750000000000000, 0.3750000000000000, 0.6250000000000000], 41 | [0.3750000000000000, 0.6250000000000000, 0.3750000000000000], 42 | [0.3750000000000000, 0.6250000000000000, 0.8750000000000000], 43 | [0.3750000000000000, 0.8750000000000000, 0.1250000000000000], 44 | [0.3750000000000000, 0.8750000000000000, 0.6250000000000000], 45 | [0.5000000000000000, 0.0000000000000000, 0.0000000000000000], 46 | [0.5000000000000000, 0.0000000000000000, 0.5000000000000000], 47 | [0.5000000000000000, 0.2500000000000000, 0.2500000000000000], 48 | [0.5000000000000000, 0.2500000000000000, 0.7500000000000000], 49 | [0.5000000000000000, 0.5000000000000000, 0.0000000000000000], 50 | [0.5000000000000000, 0.5000000000000000, 0.5000000000000000], 51 | [0.5000000000000000, 0.7500000000000000, 0.2500000000000000], 52 | [0.5000000000000000, 0.7500000000000000, 0.7500000000000000], 53 | [0.6250000000000000, 0.1250000000000000, 0.1250000000000000], 54 | [0.6250000000000000, 0.1250000000000000, 0.6250000000000000], 55 | [0.6250000000000000, 0.3750000000000000, 0.3750000000000000], 56 | [0.6250000000000000, 0.3750000000000000, 0.8750000000000000], 57 | [0.6250000000000000, 0.6250000000000000, 0.1250000000000000], 58 | [0.6250000000000000, 0.6250000000000000, 0.6250000000000000], 59 | [0.6250000000000000, 0.8750000000000000, 0.3750000000000000], 60 | [0.6250000000000000, 0.8750000000000000, 0.8750000000000000], 61 | [0.7500000000000000, 0.0000000000000000, 0.2500000000000000], 62 | [0.7500000000000000, 0.0000000000000000, 0.7500000000000000], 63 | [0.7500000000000000, 0.2500000000000000, 0.0000000000000000], 64 | [0.7500000000000000, 0.2500000000000000, 0.5000000000000000], 65 | [0.7500000000000000, 0.5000000000000000, 0.2500000000000000], 66 | [0.7500000000000000, 0.5000000000000000, 0.7500000000000000], 67 | [0.7500000000000000, 0.7500000000000000, 0.0000000000000000], 68 | [0.7500000000000000, 0.7500000000000000, 0.5000000000000000], 69 | [0.8750000000000000, 0.1250000000000000, 0.3750000000000000], 70 | [0.8750000000000000, 0.1250000000000000, 0.8750000000000000], 71 | [0.8750000000000000, 0.3750000000000000, 0.1250000000000000], 72 | [0.8750000000000000, 0.3750000000000000, 0.6250000000000000], 73 | [0.8750000000000000, 0.6250000000000000, 0.3750000000000000], 74 | [0.8750000000000000, 0.6250000000000000, 0.8750000000000000], 75 | [0.8750000000000000, 0.8750000000000000, 0.1250000000000000], 76 | [0.8750000000000000, 0.8750000000000000, 0.6250000000000000]] 77 | 78 | kd = [14] * 64 79 | 80 | force = np.loadtxt("force.dat").reshape((-1, 64, 3))[:22] 81 | disp = np.loadtxt("disp.dat").reshape((-1, 64, 3))[:22] 82 | 83 | # alm.alm_new() and alm.alm_delete() are done by 'with' statement 84 | with ALM(lavec, xcoord, kd) as alm: 85 | alm.define(2, [-1, 7.3]) 86 | alm.displacements = disp 87 | alm.forces = force 88 | alm.set_constraint(translation=False) 89 | info = alm.optimize() 90 | 91 | dependency_fc2 = alm.get_fc_dependency(1) 92 | dependency_fc3 = alm.get_fc_dependency(2) 93 | 94 | print("# dependency for FC2") 95 | for key, val in dependency_fc2.items(): 96 | print('{} = '.format(key), end='') 97 | for key2, val2 in val.items(): 98 | if val2 > 0.0: 99 | print(' +{:4.2f} {}'.format(val2, key2), end='') 100 | else: 101 | print(' {:5.2f} {}'.format(val2, key2), end='') 102 | 103 | print('') 104 | 105 | 106 | print("# dependency for FC3") 107 | for key, val in dependency_fc3.items(): 108 | print('{} = '.format(key), end='') 109 | for key2, val2 in val.items(): 110 | if val2 > 0.0: 111 | print(' +{:4.2f} {}'.format(val2, key2), end='') 112 | else: 113 | print(' {:5.2f} {}'.format(val2, key2), end='') 114 | 115 | print('') 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /example/sparse_Eigen.py: -------------------------------------------------------------------------------- 1 | # 2 | # Si_parse_Eigen.py 3 | # 4 | # This is an example to run ALM in the fitting mode with SimplicialLDLT. 5 | # 6 | 7 | from alm import ALM 8 | import numpy as np 9 | 10 | lavec = [[20.406, 0, 0], 11 | [0, 20.406, 0], 12 | [0, 0, 20.406]] 13 | xcoord = [[0.0000000000000000, 0.0000000000000000, 0.0000000000000000], 14 | [0.0000000000000000, 0.0000000000000000, 0.5000000000000000], 15 | [0.0000000000000000, 0.2500000000000000, 0.2500000000000000], 16 | [0.0000000000000000, 0.2500000000000000, 0.7500000000000000], 17 | [0.0000000000000000, 0.5000000000000000, 0.0000000000000000], 18 | [0.0000000000000000, 0.5000000000000000, 0.5000000000000000], 19 | [0.0000000000000000, 0.7500000000000000, 0.2500000000000000], 20 | [0.0000000000000000, 0.7500000000000000, 0.7500000000000000], 21 | [0.1250000000000000, 0.1250000000000000, 0.1250000000000000], 22 | [0.1250000000000000, 0.1250000000000000, 0.6250000000000000], 23 | [0.1250000000000000, 0.3750000000000000, 0.3750000000000000], 24 | [0.1250000000000000, 0.3750000000000000, 0.8750000000000000], 25 | [0.1250000000000000, 0.6250000000000000, 0.1250000000000000], 26 | [0.1250000000000000, 0.6250000000000000, 0.6250000000000000], 27 | [0.1250000000000000, 0.8750000000000000, 0.3750000000000000], 28 | [0.1250000000000000, 0.8750000000000000, 0.8750000000000000], 29 | [0.2500000000000000, 0.0000000000000000, 0.2500000000000000], 30 | [0.2500000000000000, 0.0000000000000000, 0.7500000000000000], 31 | [0.2500000000000000, 0.2500000000000000, 0.0000000000000000], 32 | [0.2500000000000000, 0.2500000000000000, 0.5000000000000000], 33 | [0.2500000000000000, 0.5000000000000000, 0.2500000000000000], 34 | [0.2500000000000000, 0.5000000000000000, 0.7500000000000000], 35 | [0.2500000000000000, 0.7500000000000000, 0.0000000000000000], 36 | [0.2500000000000000, 0.7500000000000000, 0.5000000000000000], 37 | [0.3750000000000000, 0.1250000000000000, 0.3750000000000000], 38 | [0.3750000000000000, 0.1250000000000000, 0.8750000000000000], 39 | [0.3750000000000000, 0.3750000000000000, 0.1250000000000000], 40 | [0.3750000000000000, 0.3750000000000000, 0.6250000000000000], 41 | [0.3750000000000000, 0.6250000000000000, 0.3750000000000000], 42 | [0.3750000000000000, 0.6250000000000000, 0.8750000000000000], 43 | [0.3750000000000000, 0.8750000000000000, 0.1250000000000000], 44 | [0.3750000000000000, 0.8750000000000000, 0.6250000000000000], 45 | [0.5000000000000000, 0.0000000000000000, 0.0000000000000000], 46 | [0.5000000000000000, 0.0000000000000000, 0.5000000000000000], 47 | [0.5000000000000000, 0.2500000000000000, 0.2500000000000000], 48 | [0.5000000000000000, 0.2500000000000000, 0.7500000000000000], 49 | [0.5000000000000000, 0.5000000000000000, 0.0000000000000000], 50 | [0.5000000000000000, 0.5000000000000000, 0.5000000000000000], 51 | [0.5000000000000000, 0.7500000000000000, 0.2500000000000000], 52 | [0.5000000000000000, 0.7500000000000000, 0.7500000000000000], 53 | [0.6250000000000000, 0.1250000000000000, 0.1250000000000000], 54 | [0.6250000000000000, 0.1250000000000000, 0.6250000000000000], 55 | [0.6250000000000000, 0.3750000000000000, 0.3750000000000000], 56 | [0.6250000000000000, 0.3750000000000000, 0.8750000000000000], 57 | [0.6250000000000000, 0.6250000000000000, 0.1250000000000000], 58 | [0.6250000000000000, 0.6250000000000000, 0.6250000000000000], 59 | [0.6250000000000000, 0.8750000000000000, 0.3750000000000000], 60 | [0.6250000000000000, 0.8750000000000000, 0.8750000000000000], 61 | [0.7500000000000000, 0.0000000000000000, 0.2500000000000000], 62 | [0.7500000000000000, 0.0000000000000000, 0.7500000000000000], 63 | [0.7500000000000000, 0.2500000000000000, 0.0000000000000000], 64 | [0.7500000000000000, 0.2500000000000000, 0.5000000000000000], 65 | [0.7500000000000000, 0.5000000000000000, 0.2500000000000000], 66 | [0.7500000000000000, 0.5000000000000000, 0.7500000000000000], 67 | [0.7500000000000000, 0.7500000000000000, 0.0000000000000000], 68 | [0.7500000000000000, 0.7500000000000000, 0.5000000000000000], 69 | [0.8750000000000000, 0.1250000000000000, 0.3750000000000000], 70 | [0.8750000000000000, 0.1250000000000000, 0.8750000000000000], 71 | [0.8750000000000000, 0.3750000000000000, 0.1250000000000000], 72 | [0.8750000000000000, 0.3750000000000000, 0.6250000000000000], 73 | [0.8750000000000000, 0.6250000000000000, 0.3750000000000000], 74 | [0.8750000000000000, 0.6250000000000000, 0.8750000000000000], 75 | [0.8750000000000000, 0.8750000000000000, 0.1250000000000000], 76 | [0.8750000000000000, 0.8750000000000000, 0.6250000000000000]] 77 | 78 | kd = [14] * 64 79 | 80 | force = np.loadtxt("force.dat").reshape((-1, 64, 3))[:22] 81 | disp = np.loadtxt("disp.dat").reshape((-1, 64, 3))[:22] 82 | 83 | with ALM(lavec, xcoord, kd) as alm: 84 | # Set displacement and force data 85 | alm.set_displacement_and_force(disp, force) 86 | 87 | # Define the taylor expansion model and find force constants 88 | alm.define(2, [-1, 7.3]) 89 | 90 | # Set up options for translational invariance 91 | alm.set_constraint(translation=True) 92 | 93 | # Run fitting by internal function 94 | alm.optimize() 95 | fc_values1, elem_indices1 = alm.get_fc(2) 96 | 97 | # Run fitting by interal sparse solver 98 | alm.optimize(solver='SimplicialLDLT') 99 | fc_values2, elem_indices2 = alm.get_fc(2) 100 | 101 | c = "xyz" 102 | 103 | diffs = [] 104 | for (fc, fc_sparse, elem) in zip(fc_values1, fc_values2, elem_indices2): 105 | v1 = elem[0] // 3 106 | c1 = elem[0] % 3 107 | v2 = elem[1] // 3 108 | c2 = elem[1] % 3 109 | diffs.append(fc - fc_sparse) 110 | print("%15.7f %15.7f %15.6e %d%s %d%s" % 111 | ((fc, fc_sparse, fc - fc_sparse, v1 + 1, c[c1], v2 + 1, c[c2]))) 112 | 113 | print("") 114 | print("* Largest difference between dense and sparse solvers: %e" 115 | % np.max(np.abs(diffs))) 116 | -------------------------------------------------------------------------------- /example/write_fcsxml.py: -------------------------------------------------------------------------------- 1 | # 2 | # write_fcsxml.py 3 | # 4 | # This is an example to run ALM in the suggest mode. 5 | # 6 | 7 | from alm import ALM 8 | from alm.fcsxml import Fcsxml 9 | import numpy as np 10 | 11 | lavec = [[20.406, 0, 0], 12 | [0, 20.406, 0], 13 | [0, 0, 20.406]] 14 | xcoord = [[0.0000000000000000, 0.0000000000000000, 0.0000000000000000], 15 | [0.0000000000000000, 0.0000000000000000, 0.5000000000000000], 16 | [0.0000000000000000, 0.2500000000000000, 0.2500000000000000], 17 | [0.0000000000000000, 0.2500000000000000, 0.7500000000000000], 18 | [0.0000000000000000, 0.5000000000000000, 0.0000000000000000], 19 | [0.0000000000000000, 0.5000000000000000, 0.5000000000000000], 20 | [0.0000000000000000, 0.7500000000000000, 0.2500000000000000], 21 | [0.0000000000000000, 0.7500000000000000, 0.7500000000000000], 22 | [0.1250000000000000, 0.1250000000000000, 0.1250000000000000], 23 | [0.1250000000000000, 0.1250000000000000, 0.6250000000000000], 24 | [0.1250000000000000, 0.3750000000000000, 0.3750000000000000], 25 | [0.1250000000000000, 0.3750000000000000, 0.8750000000000000], 26 | [0.1250000000000000, 0.6250000000000000, 0.1250000000000000], 27 | [0.1250000000000000, 0.6250000000000000, 0.6250000000000000], 28 | [0.1250000000000000, 0.8750000000000000, 0.3750000000000000], 29 | [0.1250000000000000, 0.8750000000000000, 0.8750000000000000], 30 | [0.2500000000000000, 0.0000000000000000, 0.2500000000000000], 31 | [0.2500000000000000, 0.0000000000000000, 0.7500000000000000], 32 | [0.2500000000000000, 0.2500000000000000, 0.0000000000000000], 33 | [0.2500000000000000, 0.2500000000000000, 0.5000000000000000], 34 | [0.2500000000000000, 0.5000000000000000, 0.2500000000000000], 35 | [0.2500000000000000, 0.5000000000000000, 0.7500000000000000], 36 | [0.2500000000000000, 0.7500000000000000, 0.0000000000000000], 37 | [0.2500000000000000, 0.7500000000000000, 0.5000000000000000], 38 | [0.3750000000000000, 0.1250000000000000, 0.3750000000000000], 39 | [0.3750000000000000, 0.1250000000000000, 0.8750000000000000], 40 | [0.3750000000000000, 0.3750000000000000, 0.1250000000000000], 41 | [0.3750000000000000, 0.3750000000000000, 0.6250000000000000], 42 | [0.3750000000000000, 0.6250000000000000, 0.3750000000000000], 43 | [0.3750000000000000, 0.6250000000000000, 0.8750000000000000], 44 | [0.3750000000000000, 0.8750000000000000, 0.1250000000000000], 45 | [0.3750000000000000, 0.8750000000000000, 0.6250000000000000], 46 | [0.5000000000000000, 0.0000000000000000, 0.0000000000000000], 47 | [0.5000000000000000, 0.0000000000000000, 0.5000000000000000], 48 | [0.5000000000000000, 0.2500000000000000, 0.2500000000000000], 49 | [0.5000000000000000, 0.2500000000000000, 0.7500000000000000], 50 | [0.5000000000000000, 0.5000000000000000, 0.0000000000000000], 51 | [0.5000000000000000, 0.5000000000000000, 0.5000000000000000], 52 | [0.5000000000000000, 0.7500000000000000, 0.2500000000000000], 53 | [0.5000000000000000, 0.7500000000000000, 0.7500000000000000], 54 | [0.6250000000000000, 0.1250000000000000, 0.1250000000000000], 55 | [0.6250000000000000, 0.1250000000000000, 0.6250000000000000], 56 | [0.6250000000000000, 0.3750000000000000, 0.3750000000000000], 57 | [0.6250000000000000, 0.3750000000000000, 0.8750000000000000], 58 | [0.6250000000000000, 0.6250000000000000, 0.1250000000000000], 59 | [0.6250000000000000, 0.6250000000000000, 0.6250000000000000], 60 | [0.6250000000000000, 0.8750000000000000, 0.3750000000000000], 61 | [0.6250000000000000, 0.8750000000000000, 0.8750000000000000], 62 | [0.7500000000000000, 0.0000000000000000, 0.2500000000000000], 63 | [0.7500000000000000, 0.0000000000000000, 0.7500000000000000], 64 | [0.7500000000000000, 0.2500000000000000, 0.0000000000000000], 65 | [0.7500000000000000, 0.2500000000000000, 0.5000000000000000], 66 | [0.7500000000000000, 0.5000000000000000, 0.2500000000000000], 67 | [0.7500000000000000, 0.5000000000000000, 0.7500000000000000], 68 | [0.7500000000000000, 0.7500000000000000, 0.0000000000000000], 69 | [0.7500000000000000, 0.7500000000000000, 0.5000000000000000], 70 | [0.8750000000000000, 0.1250000000000000, 0.3750000000000000], 71 | [0.8750000000000000, 0.1250000000000000, 0.8750000000000000], 72 | [0.8750000000000000, 0.3750000000000000, 0.1250000000000000], 73 | [0.8750000000000000, 0.3750000000000000, 0.6250000000000000], 74 | [0.8750000000000000, 0.6250000000000000, 0.3750000000000000], 75 | [0.8750000000000000, 0.6250000000000000, 0.8750000000000000], 76 | [0.8750000000000000, 0.8750000000000000, 0.1250000000000000], 77 | [0.8750000000000000, 0.8750000000000000, 0.6250000000000000]] 78 | 79 | kd = [14] * 64 80 | 81 | force = np.loadtxt("force.dat").reshape((-1, 64, 3))[:22] 82 | disp = np.loadtxt("disp.dat").reshape((-1, 64, 3))[:22] 83 | 84 | fc_values = [] 85 | elem_indices = [] 86 | fc3_values = [] 87 | elem3_indices = [] 88 | 89 | with ALM(lavec, xcoord, kd) as alm: 90 | alm.define(2, [-1, 7.3]) 91 | alm.displacements = disp 92 | alm.forces = force 93 | info = alm.optimize() 94 | fc_values, elem_indices = alm.get_fc(1) # harmonic fc 95 | fc3_values, elem3_indices = alm.get_fc(2) # cubic fc 96 | alm.save_fc(filename="anharmonic.xml", format="alamode") 97 | 98 | 99 | 100 | kd = [14] * 64 101 | obj = Fcsxml(lavec, xcoord, kd) 102 | 103 | obj.set_force_constants(fc_values, elem_indices) 104 | obj.set_force_constants(fc3_values, elem3_indices) 105 | 106 | # The contents of test.xml should be the same as that of anharmonic.xml 107 | obj.write(filename="test.xml") 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /python/alm/__init__.py: -------------------------------------------------------------------------------- 1 | """ALM package.""" 2 | from .alm import ALM, optimizer_control_data_types 3 | 4 | assert ALM 5 | 6 | assert optimizer_control_data_types 7 | -------------------------------------------------------------------------------- /python/alm_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef __ALM_WRAPPER_H__ 2 | #define __ALM_WRAPPER_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | struct optimizer_control { 9 | int linear_model; // 1 : least-squares, 2 : elastic net 10 | int use_sparse_solver; // 0: No, 1: Yes 11 | int maxnum_iteration; 12 | double tolerance_iteration; 13 | int output_frequency; 14 | 15 | // Options related to L1-regularized optimization 16 | int standardize; 17 | double displacement_normalization_factor; 18 | int debiase_after_l1opt; 19 | 20 | // cross-validation related variables 21 | int cross_validation; // 0 : No CV mode, -1 or > 0: CV mode 22 | double l1_alpha; // L1-regularization coefficient 23 | double l1_alpha_min; 24 | double l1_alpha_max; 25 | int num_l1_alpha; 26 | double l1_ratio; // l1_ratio = 1 for LASSO; 0 < l1_ratio < 1 for Elastic net 27 | int save_solution_path; 28 | int mirror_image_conv; 29 | }; 30 | 31 | void alm_init(void); 32 | int alm_new(void); 33 | void alm_delete(const int id); 34 | void alm_define(const int id, 35 | const int maxorder, 36 | const size_t nkd, 37 | const int *nbody_include, 38 | const double *cutoff_radii_in, 39 | const char *fc_basis); 40 | void alm_suggest(const int id); 41 | int alm_optimize(const int id, 42 | const char *solver); 43 | void alm_init_fc_table(const int id); 44 | void alm_set_optimizer_control(const int id, 45 | const struct optimizer_control optcontrol, 46 | const int updated[15]); 47 | void alm_set_cell(const int id, 48 | const size_t nat, 49 | const double lavec[3][3], 50 | const double xcoord[][3], 51 | const int numbers[], 52 | const size_t nkind, 53 | const int kind_numbers[]); 54 | void alm_set_verbosity(const int id, 55 | const int verbosity); 56 | void alm_set_u_train(const int id, 57 | const double *u_in, 58 | const size_t nat, 59 | const size_t ndata_used); 60 | void alm_set_f_train(const int id, 61 | const double *f_in, 62 | const size_t nat, 63 | const size_t ndata_used); 64 | void alm_set_constraint_type(const int id, 65 | const int constraint_flag); // ICONST 66 | void alm_set_forceconstants_to_fix(const int id, 67 | const int *fc_indices, 68 | const double *fc_values, 69 | const size_t nfcs, 70 | const int fc_order); // harmonic=1 71 | void alm_set_fc(const int id, double *fc_in); 72 | 73 | void alm_set_output_filename_prefix(const int id, 74 | const char *prefix_in); 75 | // void set_magnetic_params(const double* const * magmom, 76 | // const bool lspin, 77 | // const int noncollinear, 78 | // const int trev_sym_mag, 79 | // const std::string str_magmom); 80 | // void set_fitting_constraint_rotation_axis(const std::string rotation_axis) // ROTAXIS 81 | // void set_fitting_filenames(const std::string dfile, 82 | // const std::string ffile); 83 | struct optimizer_control alm_get_optimizer_control(const int id); 84 | int alm_get_u_train(const int id, double *u_out, const int nelems_in); 85 | int alm_get_f_train(const int id, double *f_out, const int nelems_in); 86 | double alm_get_cv_l1_alpha(const int id); 87 | int alm_get_atom_mapping_by_pure_translations(const int id, 88 | int *map_p2s); 89 | size_t alm_get_number_of_displacement_patterns(const int id, 90 | const int fc_order); // harmonic=1, 91 | void alm_get_number_of_displaced_atoms(const int id, 92 | int *numbers, 93 | const int fc_order); // harmonic=1, 94 | size_t alm_get_number_of_data(const int id); 95 | size_t alm_get_nrows_sensing_matrix(const int id); 96 | int alm_get_displacement_patterns(const int id, 97 | int *atom_indices, 98 | double *disp_patterns, 99 | const int fc_order); // harmonic=1, 100 | size_t alm_get_number_of_fc_elements(const int id, 101 | const int fc_order); // harmonic=1, ... 102 | size_t alm_get_number_of_fc_origin(const int id, 103 | const int fc_order, // harmonic=1, ... 104 | const int permutation); 105 | size_t alm_get_number_of_irred_fc_elements(const int id, 106 | const int fc_order); // harmonic=1, ... 107 | void alm_get_fc_origin(const int id, 108 | double *fc_value, 109 | int *elem_indices, // (len(fc_value), fc_order + 1) is flatten. 110 | const int fc_order, 111 | const int permutation); 112 | void alm_get_fc_irreducible(const int id, 113 | double *fc_value, 114 | int *elem_indices, // (len(fc_value), fc_order + 1) is flatten. 115 | const int fc_order); 116 | void alm_get_fc_all(const int id, 117 | double *fc_value, 118 | int *elem_indices, // (len(fc_value), fc_order + 1) is flatten. 119 | const int fc_order, 120 | const int permutation); 121 | void alm_get_matrix_elements(const int id, 122 | double *amat, 123 | double *bvec); 124 | 125 | void alm_save_fc(const int id, 126 | const char *filename, 127 | const char *format, 128 | const int maxorder_to_save); 129 | 130 | void alm_get_fc_dependency(const int id, 131 | int *elem_indices_irred, 132 | int *elem_indices_orig, 133 | double *dependency_mat, 134 | const int fc_order); 135 | 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /python/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools", "wheel", "numpy"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "alm" 7 | version = "1.4.0" 8 | description = "Force constants generator" 9 | authors = [ 10 | {name = "Terumasa Tadano"}, 11 | {email = "terumasa.tadano@gmail.com" } 12 | ] 13 | readme = "README.md" 14 | license = { text = "MIT License"} 15 | keywords = ["alm", "numpy", "setuptools"] 16 | 17 | [project.urls] 18 | documentation = "https://alm.readthedocs.io" 19 | homepage = "https://github.com/ttadano/ALM" 20 | repository = "https://github.com/ttadano/ALM" 21 | 22 | [project.scripts] 23 | alm = "alm:main" 24 | 25 | [tool.flake8] 26 | max-line-length = 88 27 | extend-ignore = "E203,W503" 28 | 29 | [tool.black] 30 | line-length = 88 31 | 32 | [tool.isort] 33 | profile = "black" 34 | -------------------------------------------------------------------------------- /python/setup.cfg: -------------------------------------------------------------------------------- 1 | [options] 2 | package_dir= 3 | =. 4 | packages=find: 5 | 6 | [options.packages.find] 7 | where=. 8 | -------------------------------------------------------------------------------- /python/setup.py: -------------------------------------------------------------------------------- 1 | """Setuptools script for building alm package.""" 2 | 3 | import os 4 | import warnings 5 | 6 | import numpy 7 | from setuptools import Extension, setup 8 | 9 | try: 10 | from pathlib import Path 11 | 12 | home = str(Path.home()) 13 | except ImportError: 14 | home = os.path.expanduser("~") 15 | 16 | # This is the switch for ALM development. Always True for general cases. 17 | compile_with_sources = True 18 | 19 | # Configurations to pass to extension. 20 | # The following directory structure and use of conda are supposed. 21 | # 22 | # $HOME 23 | # |-- ALM 24 | # | `-- ALM 25 | # | |-- bin/ 26 | # | |-- include/ 27 | # | |-- lib/ 28 | # | |-- python/setup.py 29 | # | |-- src/ 30 | # | |-- _build/ 31 | # | |-- CMakeLists.txt 32 | # | `-- ... 33 | # | 34 | # |-- $CONDA_PREFIX/include 35 | # |-- $CONDA_PREFIX/include/eigen3 36 | # |-- $CONDA_PREFIX/lib 37 | # `-- ... 38 | 39 | if "CONDA_PREFIX" in os.environ: 40 | conda_prefix = os.environ["CONDA_PREFIX"] 41 | else: 42 | conda_prefix = os.path.join(home, "miniconda", "envs", "alm") 43 | 44 | library_dirs = [] 45 | extra_link_args = [] 46 | 47 | # OpenMP library 48 | if "CC" in os.environ: 49 | if "clang" in os.environ["CC"]: 50 | if "clang++" not in os.environ["CC"]: 51 | warnings.warn("clang++ is used instead of clang.") 52 | os.environ["CC"] = os.environ["CC"].replace("clang", "clang++") 53 | extra_link_args.append("-lomp") 54 | elif "gcc" in os.environ["CC"]: 55 | if "g++" not in os.environ["CC"]: 56 | warnings.warn("g++ is used instead of gcc.") 57 | os.environ["CC"] = os.environ["CC"].replace("gcc", "g++") 58 | extra_link_args.append("-lgomp") 59 | elif "gnu-cc" in os.environ["CC"]: 60 | if "gnu-c++" not in os.environ["CC"]: 61 | warnings.warn("gnu-g++ is used instead of gnu-cc.") 62 | os.environ["CC"] = os.environ["CC"].replace("gnu-cc", "gnu-c++") 63 | extra_link_args.append("-lgomp") 64 | 65 | if not extra_link_args: # Default libgomp 66 | extra_link_args.append("-lgomp") 67 | 68 | # Lapack library 69 | extra_link_args.append("-llapack") 70 | 71 | # spglib 72 | extra_link_args.append("-lsymspg") 73 | 74 | include_dirs = [] 75 | include_dirs.append(numpy.get_include()) 76 | include_dirs.append(os.path.join(conda_prefix, "include")) 77 | include_dirs.append(os.path.join(conda_prefix, "include", "eigen3")) 78 | 79 | 80 | if compile_with_sources: 81 | cpp_files = [ 82 | "alm.cpp", 83 | "cluster.cpp", 84 | "constraint.cpp", 85 | "fcs.cpp", 86 | "files.cpp", 87 | "optimize.cpp", 88 | "patterndisp.cpp", 89 | "rref.cpp", 90 | "symmetry.cpp", 91 | "system.cpp", 92 | "timer.cpp", 93 | "writer.cpp", 94 | ] 95 | if os.path.exists("src"): 96 | source_dir = "src" 97 | else: 98 | source_dir = os.path.join("..", "src") 99 | 100 | include_dirs += [ 101 | source_dir, 102 | ] 103 | sources = [os.path.join(source_dir, s) for s in cpp_files] 104 | sources += ["_alm.c", "alm_wrapper.cpp"] 105 | else: # compile with library 106 | sources = ["_alm.c", "alm_wrapper.cpp"] 107 | # 'libalmcxx.a' static link library has to come before depending 108 | # dynamic link libraries '-lgomp', '-llapack'. 109 | extra_link_args.insert(0, os.path.join("..", "lib", "libalmcxx.a")) 110 | 111 | extension = Extension( 112 | "alm._alm", 113 | include_dirs=include_dirs, 114 | library_dirs=library_dirs, 115 | extra_compile_args=["-fopenmp", "-std=c++11"], 116 | extra_link_args=extra_link_args, 117 | sources=sources, 118 | ) 119 | 120 | setup( 121 | platforms=["all"], 122 | ext_modules=[extension], 123 | ) 124 | -------------------------------------------------------------------------------- /src/Makefile.linux: -------------------------------------------------------------------------------- 1 | .SUFFIXES: .h .cpp 2 | #----------------------------------------------- 3 | # Makefile for the program 'ALM'. 4 | # Please modify the variables properly. 5 | # We recommend to use Intel c++ compiler. 6 | #----------------------------------------------- 7 | 8 | CXX = icpc 9 | CXXFLAGS = -O2 -xHOST -qopenmp -std=c++11 10 | INCLUDE = -I../include -I$(HOME)/include -I$(SPGLIB_ROOT)/include 11 | 12 | CXXL = ${CXX} 13 | LDFLAGS = -mkl -L$(SPGLIB_ROOT)/lib -lsymspg 14 | 15 | LAPACK = 16 | LIBS = ${LAPACK} 17 | 18 | #----------------------------------------------- 19 | # General rules 20 | #----------------------------------------------- 21 | 22 | .cpp.o: 23 | ${CXX} ${CXXFLAGS} ${INCLUDE} -c $< 24 | 25 | PROG = alm 26 | 27 | CXXSRC= $(wildcard *.cpp) 28 | 29 | OBJS= ${CXXSRC:.cpp=.o} 30 | 31 | default: alm 32 | 33 | all: ${PROG} 34 | 35 | alm: ${OBJS} 36 | ${CXXL} ${LDFLAGS} -o $@ ${OBJS} ${LIBS} 37 | 38 | clean: 39 | rm -f ${OBJS} 40 | 41 | .PHONY: clean 42 | 43 | depend: 44 | gcc -MM *.cpp > .depend 45 | 46 | -include .depend 47 | -------------------------------------------------------------------------------- /src/Makefile.osx: -------------------------------------------------------------------------------- 1 | .SUFFIXES: .h .cpp 2 | #----------------------------------------------- 3 | # Makefile for the program 'ALM'. 4 | # Please modify the variables properly. 5 | # We recommend to use Intel c++ compiler. 6 | #----------------------------------------------- 7 | 8 | # Use gcc >= 4.8 to use OpenMP 9 | # OpenMP-enabled gcc can be installed via homebrew 10 | CXX = g++-9 11 | CXXFLAGS = -O2 -fopenmp -std=c++11 12 | INCLUDE = -I../include -I$(HOME)/include -I$(SPGLIB_ROOT)/include -I/usr/local/include/eigen3/ -I/usr/local/include/ 13 | 14 | CXXL = ${CXX} 15 | LDFLAGS = -lgomp -L$(SPGLIB_ROOT)/lib -lsymspg 16 | 17 | LAPACK = -llapack -lblas 18 | LIBS = ${LAPACK} 19 | 20 | #----------------------------------------------- 21 | # General rules 22 | #----------------------------------------------- 23 | 24 | .cpp.o: 25 | ${CXX} ${CXXFLAGS} ${INCLUDE} -c $< 26 | 27 | PROG = alm 28 | 29 | CXXSRC= $(wildcard *.cpp) 30 | 31 | OBJS= ${CXXSRC:.cpp=.o} 32 | 33 | default: alm 34 | 35 | all: ${PROG} 36 | 37 | alm: ${OBJS} 38 | ${CXXL} ${LDFLAGS} -o $@ ${OBJS} ${LIBS} 39 | 40 | clean: 41 | rm -f ${OBJS} 42 | 43 | .PHONY: clean 44 | 45 | depend: 46 | gcc -MM *.cpp > .depend 47 | 48 | -include .depend 49 | -------------------------------------------------------------------------------- /src/alm.h: -------------------------------------------------------------------------------- 1 | /* 2 | alm.h 3 | 4 | Copyright (c) 2014, 2015, 2016 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include "system.h" 15 | #include "cluster.h" 16 | #include "fcs.h" 17 | #include "symmetry.h" 18 | #include "optimize.h" 19 | #include "constraint.h" 20 | #include "files.h" 21 | #include "patterndisp.h" 22 | #include "timer.h" 23 | #include "writer.h" 24 | 25 | namespace ALM_NS { 26 | class ALM { 27 | public: 28 | ALM(); 29 | 30 | ~ALM(); 31 | 32 | class Cluster *cluster{}; 33 | 34 | class Fcs *fcs{}; 35 | 36 | class System *system{}; 37 | 38 | class Symmetry *symmetry{}; 39 | 40 | class Optimize *optimize{}; 41 | 42 | class Constraint *constraint{}; 43 | 44 | class Files *files{}; 45 | 46 | class Displace *displace{}; 47 | 48 | class Timer *timer{}; 49 | 50 | class Writer *writer{}; 51 | 52 | void set_verbosity(int verbosity_in); 53 | 54 | int get_verbosity() const; 55 | 56 | void set_output_filename_prefix(std::string prefix) const; 57 | 58 | void set_print_symmetry(int printsymmetry) const; 59 | 60 | void set_datfile_train(const DispForceFile &dat_in) const; 61 | 62 | void set_datfile_validation(const DispForceFile &dat_in) const; 63 | 64 | void set_symmetry_tolerance(double tolerance) const; 65 | 66 | void set_displacement_param(bool trim_dispsign_for_evenfunc) const; 67 | 68 | void set_displacement_basis(std::string str_disp_basis) const; 69 | 70 | void set_periodicity(const int is_periodic[3]) const; 71 | 72 | void set_cell(size_t nat, 73 | const double lavec[3][3], 74 | const double xcoord[][3], 75 | const int kind[], 76 | const std::string kdname[]) const; 77 | 78 | void set_magnetic_params(const size_t nat, 79 | const double (*magmom)[3], 80 | const bool lspin, 81 | const int noncollinear, 82 | const int trev_sym_mag, 83 | const std::string str_magmom) const; 84 | 85 | void set_u_train(const std::vector> &u) const; 86 | 87 | void set_f_train(const std::vector> &f) const; 88 | 89 | void set_validation_data(const std::vector> &u, 90 | const std::vector> &f) const; 91 | 92 | void set_optimizer_control(const OptimizerControl &optcontrol_in) const; 93 | 94 | void set_constraint_mode(const int constraint_flag) const; 95 | 96 | void set_algebraic_constraint(const int use_algebraic_flag) const; 97 | 98 | void set_tolerance_constraint(const double tolerance_constraint) const; 99 | 100 | void set_rotation_axis(const std::string rotation_axis) const; 101 | 102 | void set_fc_file(const int order, const std::string fc_file) const; 103 | 104 | void set_fc_fix(const int order, const bool fc_fix) const; 105 | 106 | bool ready_all_constraints() const; 107 | 108 | void set_forceconstants_to_fix(const std::vector> &intpair_fix, 109 | const std::vector &values_fix) const; 110 | 111 | void set_sparse_mode(const int sparse_mode) const; 112 | 113 | void set_forceconstant_basis(const std::string preferred_basis) const; 114 | 115 | std::string get_forceconstant_basis() const; 116 | 117 | void set_nmaxsave(const int nmaxsave) const; // NMAXSAVE 118 | 119 | int get_nmaxsave() const; 120 | 121 | //void set_fitting_filenames(std::string dfile, 122 | // std::string ffile) const; 123 | void define(const int maxorder, 124 | const size_t nkd, 125 | const int *nbody_include, 126 | const double *cutoff_radii) const; 127 | 128 | //int get_ndata_used() const; 129 | OptimizerControl get_optimizer_control() const; 130 | 131 | std::vector> get_u_train() const; 132 | 133 | std::vector> get_f_train() const; 134 | 135 | size_t get_number_of_data() const; 136 | 137 | size_t get_nrows_sensing_matrix() const; 138 | 139 | double get_cv_l1_alpha() const; 140 | 141 | Cell get_supercell() const; 142 | 143 | std::string *get_kdname() const; 144 | 145 | Spin get_spin() const; 146 | 147 | void set_str_magmom(std::string); 148 | 149 | std::string get_str_magmom() const; 150 | 151 | double ***get_x_image() const; 152 | 153 | int *get_periodicity() const; 154 | 155 | const std::vector> &get_atom_mapping_by_pure_translations() const; 156 | 157 | int get_maxorder() const; 158 | 159 | int *get_nbody_include() const; 160 | 161 | size_t get_number_of_displacement_patterns(const int fc_order) const; // harmonic=1, ... 162 | void get_number_of_displaced_atoms(int *numbers, 163 | int fc_order) const; // harmonic=1, ... 164 | int get_displacement_patterns(int *atom_indices, 165 | double *disp_patterns, 166 | int fc_order) const; // harmonic=1, ... 167 | size_t get_number_of_fc_elements(const int fc_order) const; // harmonic=1, ... 168 | size_t get_number_of_irred_fc_elements(const int fc_order); // harmonic=1, ... 169 | 170 | size_t get_number_of_fc_origin(const int fc_order, // harmonic = 1 171 | const int permutation) const; 172 | 173 | void get_fc_origin(double *fc_values, 174 | int *elem_indices, // (len(fc_value), fc_order) is flatten. 175 | int fc_order, // harmonic=1, ... 176 | int permutation = 1) const; 177 | 178 | 179 | void get_fc_irreducible(double *fc_values, 180 | int *elem_indices, // (len(fc_value), fc_order) is flatten. 181 | int fc_order); // harmonic=1, ... 182 | 183 | 184 | void get_fc_all(double *fc_values, 185 | int *elem_indices, // (len(fc_value), fc_order) is flatten. 186 | int fc_order, // harmonic=1, ... 187 | int permutation = 1) const; 188 | 189 | void get_fc_dependency_mat(const int fc_order, 190 | int *index_elements_irred, 191 | int *index_elements_origin, 192 | double *matrix_out) const; 193 | 194 | void set_fc(double *fc_in) const; 195 | 196 | void set_fc_zero_threshold(const double threshold_in); 197 | 198 | double get_fc_zero_threshold() const; 199 | 200 | void get_matrix_elements(double *amat, 201 | double *bvec); 202 | 203 | int run_optimize(); 204 | 205 | void run_suggest(); 206 | 207 | void init_fc_table(); 208 | 209 | void save_fc(const std::string filename, 210 | const std::string fc_format, 211 | const int maxorder_to_save) const; 212 | 213 | void set_fcs_save_flag(const std::string fcs_format, const int val) const; 214 | 215 | int get_fcs_save_flag(const std::string fcs_format) const; 216 | 217 | private: 218 | 219 | int verbosity; 220 | bool structure_initialized; 221 | bool initialized_constraint_class; 222 | std::ofstream *ofs_alm; 223 | std::streambuf *coutbuf; 224 | 225 | void init_instances(); 226 | }; 227 | } 228 | -------------------------------------------------------------------------------- /src/alm_cui.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | alm_cui.cpp 3 | 4 | Copyright (c) 2014, 2015, 2016 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #include "alm_cui.h" 12 | #include "alm.h" 13 | #include "input_parser.h" 14 | #include "timer.h" 15 | #include "version.h" 16 | #include 17 | #include 18 | 19 | #ifdef _OPENMP 20 | 21 | #include 22 | 23 | #endif 24 | 25 | using namespace ALM_NS; 26 | 27 | ALMCUI::ALMCUI() {} 28 | 29 | ALMCUI::~ALMCUI() {} 30 | 31 | void ALMCUI::run(const int narg, 32 | char **arg) const 33 | { 34 | auto alm = new ALM(); 35 | 36 | // alm->mode is set herein. 37 | auto input_parser = new InputParser(); 38 | input_parser->run(alm, narg, arg); 39 | auto run_mode = input_parser->get_run_mode(); 40 | delete input_parser; 41 | 42 | if (alm->get_verbosity() > 0) { 43 | std::cout << " +-----------------------------------------------------------------+" << std::endl; 44 | std::cout << " + Program ALM +" << std::endl; 45 | std::cout << " + Ver."; 46 | std::cout << std::setw(7) << ALAMODE_VERSION; 47 | std::cout << " +" << std::endl; 48 | std::cout << " +-----------------------------------------------------------------+" << std::endl; 49 | std::cout << std::endl; 50 | #ifdef _OPENMP 51 | std::cout << " Number of OpenMP threads = " 52 | << omp_get_max_threads() << std::endl << std::endl; 53 | #endif 54 | 55 | std::cout << " Job started at " << alm->timer->DateAndTime() << std::endl; 56 | } 57 | 58 | if (alm->get_verbosity() > 0) { 59 | alm->writer->write_input_vars(alm->system, 60 | alm->symmetry, 61 | alm->cluster, 62 | alm->displace, 63 | alm->fcs, 64 | alm->constraint, 65 | alm->optimize, 66 | alm->files, 67 | run_mode); 68 | } 69 | 70 | alm->init_fc_table(); 71 | 72 | if (run_mode == "optimize") { 73 | alm->run_optimize(); 74 | if (alm->get_optimizer_control().linear_model == 1 || 75 | (alm->get_optimizer_control().linear_model >= 2 76 | && alm->get_optimizer_control().cross_validation == 0)) { 77 | alm->writer->writeall(alm->system, 78 | alm->symmetry, 79 | alm->cluster, 80 | alm->constraint, 81 | alm->fcs, 82 | alm->optimize, 83 | alm->files, 84 | alm->get_verbosity()); 85 | 86 | const auto nfcs_irred = alm->get_number_of_irred_fc_elements(2); 87 | const auto nfcs_origin = alm->get_number_of_fc_origin(2, 0); 88 | 89 | std::cout << nfcs_irred << " " << nfcs_origin << '\n'; 90 | 91 | double *flattened_array = new double[nfcs_irred * nfcs_origin]; 92 | int *index_elements_origin = new int[nfcs_origin * 3]; 93 | int *index_elements_irred = new int[nfcs_irred * 3]; 94 | 95 | alm->get_fc_dependency_mat(2, 96 | index_elements_irred, 97 | index_elements_origin, 98 | flattened_array); 99 | 100 | for (size_t i = 0; i < nfcs_origin; ++i) { 101 | for (size_t j = 0; j < nfcs_irred; ++j) { 102 | std::cout << flattened_array[i * nfcs_irred + j] << " "; 103 | } 104 | std::cout << '\n'; 105 | } 106 | 107 | delete[] flattened_array; 108 | delete[] index_elements_irred; 109 | delete[] index_elements_origin; 110 | 111 | } 112 | } else if (run_mode == "suggest") { 113 | alm->run_suggest(); 114 | alm->writer->write_displacement_pattern(alm->cluster, 115 | alm->displace, 116 | alm->files->get_prefix(), 117 | alm->get_verbosity()); 118 | } 119 | 120 | if (alm->get_verbosity() > 0) { 121 | std::cout << std::endl << " Job finished at " 122 | << alm->timer->DateAndTime() << std::endl; 123 | } 124 | 125 | delete alm; 126 | } 127 | -------------------------------------------------------------------------------- /src/alm_cui.h: -------------------------------------------------------------------------------- 1 | /* 2 | almcui.h 3 | 4 | Copyright (c) 2014, 2015, 2016 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | 12 | #pragma once 13 | 14 | namespace ALM_NS { 15 | class ALMCUI { 16 | public: 17 | ALMCUI(); 18 | 19 | ~ALMCUI(); 20 | 21 | void run(const int narg, 22 | char **arg) const; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /src/combination.h: -------------------------------------------------------------------------------- 1 | /* 2 | combination.h 3 | 4 | Copyright (c) 2014 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include "../external/combination.hpp" 16 | 17 | namespace ALM_NS { 18 | template 19 | class CombinationWithRepetition { 20 | std::vector vec; 21 | unsigned int ndim; 22 | 23 | 24 | public: 25 | CombinationWithRepetition() {}; 26 | 27 | template 28 | CombinationWithRepetition(InputIter begin, 29 | InputIter end, 30 | const unsigned int n) 31 | { 32 | ndim = n; 33 | 34 | // remove redundunt elements 35 | std::set set_tmp; 36 | for (InputIter iter = begin; iter != end; ++iter) set_tmp.insert(*iter); 37 | 38 | vec.clear(); 39 | 40 | for (auto iter = set_tmp.begin(); iter != set_tmp.end(); ++iter) { 41 | for (unsigned int i = 0; i < ndim; i++) { 42 | vec.push_back(*iter); 43 | } 44 | } 45 | } 46 | 47 | bool next() 48 | { 49 | return boost::next_combination(vec.begin(), vec.begin() + ndim, vec.end()); 50 | } 51 | 52 | std::vector now() const 53 | { 54 | return std::vector(vec.begin(), vec.begin() + ndim); 55 | } 56 | 57 | unsigned int size() const 58 | { 59 | const unsigned int n = vec.size() / ndim; 60 | const auto r = ndim; 61 | return factorial(n + r - 1, n - 1) / factorial(r); 62 | } 63 | 64 | private: 65 | unsigned int factorial(const unsigned int max, 66 | const unsigned int min = 1) const 67 | { 68 | unsigned int result = 1; 69 | for (auto i = min + 1; i <= max; ++i) result *= i; 70 | return result; 71 | } 72 | }; 73 | } 74 | -------------------------------------------------------------------------------- /src/constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | constants.h 3 | 4 | Copyright (c) 2014 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | static const double pi = 4.0 * atan(1.0); 17 | static const double amu = 1.660538782e-27; 18 | static const double electron_mass = 9.10938215e-31; 19 | static const double amu_ry = amu / electron_mass / 2.0; 20 | static const double c_light = 299792458; 21 | static const double h_planck = 6.62606896e-34; 22 | static const double Ryd = 4.35974394e-18 / 2.0; 23 | static const double time_ry = h_planck / (2.0 * pi) / Ryd; 24 | static const double Hz_to_kayser = 1.0e-2 / (2.0 * pi * c_light); 25 | static const double Bohr_in_Angstrom = 0.52917721092; 26 | static const double k_Boltzmann = 1.3806488e-23; // J/K 27 | static const double eps = DBL_EPSILON; 28 | static const double eps15 = 1.0e-15; 29 | static const double eps12 = 1.0e-12; 30 | static const double eps10 = 1.0e-10; 31 | static const double eps8 = 1.0e-8; 32 | static const double eps6 = 1.0e-6; 33 | static const double eps4 = 1.0e-4; 34 | static const double inverse_pi = 1.0 / pi; 35 | -------------------------------------------------------------------------------- /src/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | error.h 3 | 4 | Copyright (c) 2014-2018 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | 17 | namespace ALM_NS { 18 | inline void warn(const char *file, 19 | const char *message) 20 | { 21 | std::cout << std::endl << " WARNING in " << file << " MESSAGE: " << message << std::endl; 22 | } 23 | 24 | inline void exit(const char *file, 25 | const char *message) 26 | { 27 | std::cout << std::endl << " ERROR in " << file << " MESSAGE: " << message << std::endl; 28 | std::exit(EXIT_FAILURE); 29 | } 30 | 31 | template 32 | void exit(const char *file, 33 | const char *message, 34 | const T info) 35 | { 36 | std::cout << std::endl << " ERROR in " << file << " MESSAGE: " << message << info << std::endl; 37 | std::exit(EXIT_FAILURE); 38 | } 39 | 40 | inline void exit(const char *file, 41 | const char *message, 42 | const char *info) 43 | { 44 | std::cout << std::endl << " ERROR in " << file << " MESSAGE: " << message << info << std::endl; 45 | std::exit(EXIT_FAILURE); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/files.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | files.cpp 3 | 4 | Copyright (c) 2014 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #include "files.h" 12 | 13 | using namespace ALM_NS; 14 | 15 | Files::Files() = default; 16 | 17 | Files::~Files() = default; 18 | 19 | void Files::init() 20 | { 21 | // file_fcs = job_title + ".fcs"; 22 | // file_hes = job_title + ".hessian"; 23 | } 24 | 25 | void Files::set_prefix(const std::string prefix_in) 26 | { 27 | job_title = prefix_in; 28 | } 29 | 30 | std::string Files::get_prefix() const 31 | { 32 | return job_title; 33 | } 34 | 35 | void Files::set_datfile_train(const DispForceFile &dat_in) 36 | { 37 | datfile_train = dat_in; 38 | } 39 | 40 | void Files::set_datfile_validation(const DispForceFile &dat_in) 41 | { 42 | datfile_validation = dat_in; 43 | } 44 | 45 | DispForceFile Files::get_datfile_train() const 46 | { 47 | return datfile_train; 48 | } 49 | 50 | DispForceFile Files::get_datfile_validation() const 51 | { 52 | return datfile_validation; 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/files.h: -------------------------------------------------------------------------------- 1 | /* 2 | files.h 3 | 4 | Copyright (c) 2014 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | namespace ALM_NS { 16 | class DispForceFile { 17 | public: 18 | std::string filename; 19 | size_t ndata, nstart, nend; 20 | size_t skip_s, skip_e; 21 | 22 | DispForceFile() 23 | { 24 | filename = ""; 25 | ndata = 0; 26 | nstart = 0; 27 | nend = 0; 28 | skip_s = 0; 29 | skip_e = 0; 30 | } 31 | 32 | ~DispForceFile() = default; 33 | 34 | DispForceFile(const DispForceFile &obj) = default; 35 | 36 | DispForceFile &operator=(const DispForceFile &obj) = default; 37 | }; 38 | 39 | class Files { 40 | public: 41 | Files(); 42 | 43 | ~Files(); 44 | 45 | void init(); 46 | 47 | void set_prefix(const std::string); 48 | 49 | std::string get_prefix() const; 50 | 51 | void set_datfile_train(const DispForceFile &dat_in); 52 | 53 | void set_datfile_validation(const DispForceFile &dat_in); 54 | 55 | DispForceFile get_datfile_train() const; 56 | 57 | DispForceFile get_datfile_validation() const; 58 | 59 | private: 60 | 61 | std::string job_title; 62 | DispForceFile datfile_train, datfile_validation; 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /src/input_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | input_parser.h 3 | 4 | Copyright (c) 2014, 2015, 2016 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "alm.h" 14 | #include "input_setter.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | 22 | namespace ALM_NS { 23 | class InputParser { 24 | public: 25 | InputParser(); 26 | 27 | ~InputParser(); 28 | 29 | void run(ALM *alm, 30 | const int narg, 31 | const char *const *arg); 32 | 33 | std::string str_magmom; 34 | 35 | std::string get_run_mode() const; 36 | 37 | private: 38 | std::ifstream ifs_input; 39 | bool from_stdin{}; 40 | std::string *kdname{}; 41 | std::string mode; 42 | int maxorder{}; 43 | size_t nat{}; 44 | size_t nkd{}; 45 | InputSetter *input_setter; 46 | 47 | void parse_input(ALM *alm); 48 | 49 | void parse_general_vars(ALM *alm); 50 | 51 | void parse_cell_parameter(); 52 | 53 | void parse_atomic_positions(); 54 | 55 | void parse_interaction_vars(); 56 | 57 | void parse_cutoff_radii(); 58 | 59 | void parse_optimize_vars(ALM *alm); 60 | 61 | int locate_tag(const std::string); 62 | 63 | static void split_str_by_space(const std::string, 64 | std::vector &); 65 | 66 | static bool is_endof_entry(const std::string); 67 | 68 | void get_var_dict(const std::vector &, 69 | std::map &); 71 | 72 | bool is_data_range_consistent(const DispForceFile &datfile_in) const; 73 | 74 | template 75 | void assign_val(T &, 76 | const std::string &, 77 | std::map); 78 | 79 | void parse_displacement_and_force_files(std::vector> &u, 80 | std::vector> &f, 81 | DispForceFile &datfile_in) const; 82 | }; 83 | } 84 | -------------------------------------------------------------------------------- /src/input_setter.h: -------------------------------------------------------------------------------- 1 | /* 2 | input_setter.h 3 | 4 | Copyright (c) 2014, 2015, 2016 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "alm.h" 14 | #include 15 | 16 | namespace ALM_NS { 17 | class InputSetter { 18 | public: 19 | InputSetter(); 20 | 21 | ~InputSetter(); 22 | 23 | void set_cell_parameter(const double a, 24 | const double lavec_in[3][3]); 25 | 26 | void set_atomic_positions(const size_t nat_in, 27 | const int *kd_in, 28 | const double (*xcoord_in)[3]); 29 | 30 | void set_geometric_structure(ALM *alm); 31 | 32 | void set_interaction_vars(const int maxorder_in, 33 | const int *nbody_include_in); 34 | 35 | void set_cutoff_radii(const int maxorder_in, 36 | const size_t nkd_in, 37 | const std::vector &cutoff_radii_in); 38 | 39 | void define(ALM *alm) const; 40 | 41 | void set_general_vars(ALM *alm, 42 | const std::string &prefix, 43 | const std::string &mode, 44 | int verbosity, 45 | const std::string &str_disp_basis, 46 | const std::string &str_magmom, 47 | size_t nat_in, 48 | size_t nkd_in, 49 | int printsymmetry, 50 | const int is_periodic_in[3], 51 | bool trim_dispsign_for_evenfunc, 52 | bool lspin_in, 53 | int print_hessian, 54 | int print_fcs_alamode, 55 | int print_fc3_shengbte, 56 | int print_fc2_qefc, 57 | int noncollinear_in, 58 | int trevsym_in, 59 | const std::string *kdname_in, 60 | const double *const *magmom_in, 61 | double tolerance, 62 | double tolerance_constraint, 63 | const std::string &basis_force_constant, 64 | const int nmaxsave, 65 | const double fc_zero_threshold); 66 | 67 | void set_optimize_vars(ALM *alm, 68 | const std::vector> &u_train_in, 69 | const std::vector> &f_train_in, 70 | const std::vector> &u_validation_in, 71 | const std::vector> &f_validation_in, 72 | const OptimizerControl &optcontrol_in) const; 73 | 74 | void set_file_vars(ALM *alm, 75 | const DispForceFile &datfile_train_in, 76 | const DispForceFile &datfile_validation_in) const; 77 | 78 | void set_constraint_vars(ALM *alm, 79 | int constraint_flag, 80 | const std::string &rotation_axis, 81 | const std::string &fc2_file, 82 | const std::string &fc3_file, 83 | bool fix_harmonic, 84 | bool fix_cubic) const; 85 | 86 | void set_geometric_structure(ALM *alm) const; 87 | 88 | private: 89 | size_t nat, nkd; 90 | int *kd; 91 | double lavec[3][3]; 92 | double (*xcoord)[3]; // fractional coordinate 93 | std::string *kdname; 94 | int is_periodic[3]; 95 | 96 | bool lspin; 97 | double (*magmom)[3]; 98 | int noncollinear; 99 | int trevsym; 100 | std::string str_magmom; 101 | 102 | int maxorder; 103 | int *nbody_include; 104 | double *cutoff_radii; 105 | }; 106 | } 107 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | main.cpp 3 | 4 | Copyright (c) 2014 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #include "alm_cui.h" 12 | #include 13 | 14 | using namespace ALM_NS; 15 | 16 | int main(const int argc, 17 | char **argv) 18 | { 19 | const auto alm_cui = new ALMCUI(); 20 | 21 | alm_cui->run(argc, argv); 22 | 23 | delete alm_cui; 24 | 25 | return EXIT_SUCCESS; 26 | } 27 | -------------------------------------------------------------------------------- /src/mathfunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | mathfunctions.h 3 | 4 | Copyright (c) 2014 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | template 18 | inline void matmul3(T ret[3][3], const T amat[3][3], const T bmat[3][3]) { 19 | int i, j, k; 20 | 21 | T ret_tmp[3][3]; 22 | 23 | for (i = 0; i < 3; ++i) { 24 | for (j = 0; j < 3; ++j) { 25 | ret_tmp[i][j] = 0.0; 26 | for (k = 0; k < 3; ++k) ret_tmp[i][j] += amat[i][k] * bmat[k][j]; 27 | } 28 | } 29 | 30 | for (i = 0; i < 3; ++i) { 31 | for (j = 0; j < 3; ++j) { 32 | ret[i][j] = ret_tmp[i][j]; 33 | } 34 | } 35 | } 36 | 37 | inline void transpose3(double ret[3][3], const double mat[3][3]) 38 | { 39 | for (int i = 0; i < 3; ++i) { 40 | for (int j = 0; j < 3; ++j) { 41 | ret[i][j] = mat[j][i]; 42 | } 43 | } 44 | } 45 | 46 | inline void rotvec(double vec_out[3], double vec_in[3], const double mat[3][3], char mode = 'N') 47 | { 48 | // Perform matrix x vector multiplication. 49 | // 50 | // vec_out = mat * vec_in (mode = 'N') 51 | // (mat)^{t} * vec_in (mode = 'T') 52 | // 53 | 54 | unsigned int i; 55 | double vec_tmp[3]; 56 | 57 | for (i = 0; i < 3; ++i){ 58 | vec_tmp[i] = vec_in[i]; 59 | } 60 | 61 | if (mode == 'N') { 62 | for (i = 0; i < 3; ++i){ 63 | vec_out[i] = mat[i][0] * vec_tmp[0] + mat[i][1] * vec_tmp[1] + mat[i][2] * vec_tmp[2]; 64 | } 65 | } else if (mode == 'T'){ 66 | for (i = 0; i < 3; ++i){ 67 | vec_out[i] = mat[0][i] * vec_tmp[0] + mat[1][i] * vec_tmp[1] + mat[2][i] * vec_tmp[2]; 68 | } 69 | } else { 70 | std::cout << "Invalid mode " << mode << std::endl; 71 | exit(1); 72 | } 73 | } 74 | 75 | inline void rotvec(double vec_out[3], double vec_in[3], const double **mat, char mode = 'N') 76 | { 77 | // Perform matrix x vector multiplication. 78 | // 79 | // vec_out = mat * vec_in (mode = 'N') 80 | // (mat)^{t} * vec_in (mode = 'T') 81 | // 82 | 83 | unsigned int i; 84 | double vec_tmp[3]; 85 | 86 | for (i = 0; i < 3; ++i){ 87 | vec_tmp[i] = vec_in[i]; 88 | } 89 | 90 | if (mode == 'N') { 91 | for (i = 0; i < 3; ++i){ 92 | vec_out[i] = mat[i][0] * vec_tmp[0] + mat[i][1] * vec_tmp[1] + mat[i][2] * vec_tmp[2]; 93 | } 94 | } else if (mode == 'T'){ 95 | for (i = 0; i < 3; ++i){ 96 | vec_out[i] = mat[0][i] * vec_tmp[0] + mat[1][i] * vec_tmp[1] + mat[2][i] * vec_tmp[2]; 97 | } 98 | } else { 99 | std::cout << "Invalid mode " << mode << std::endl; 100 | exit(1); 101 | } 102 | } 103 | 104 | inline void invmat3(double invmat[3][3], double mat[3][3]) 105 | { 106 | unsigned int i, j; 107 | double det; 108 | double mat_tmp[3][3]; 109 | 110 | for (i = 0; i < 3; ++i) { 111 | for (j = 0; j < 3; ++j) { 112 | mat_tmp[i][j] = mat[i][j]; 113 | } 114 | } 115 | 116 | det = mat_tmp[0][0] * mat_tmp[1][1] * mat_tmp[2][2] 117 | + mat_tmp[1][0] * mat_tmp[2][1] * mat_tmp[0][2] 118 | + mat_tmp[2][0] * mat_tmp[0][1] * mat_tmp[1][2] 119 | - mat_tmp[0][0] * mat_tmp[2][1] * mat_tmp[1][2] 120 | - mat_tmp[2][0] * mat_tmp[1][1] * mat_tmp[0][2] 121 | - mat_tmp[1][0] * mat_tmp[0][1] * mat_tmp[2][2]; 122 | 123 | if(std::abs(det) < 1.0e-12) { 124 | std::cout << "invmat3: Given matrix is singular" << std::endl; 125 | exit(1); 126 | } 127 | 128 | double factor = 1.0 / det; 129 | 130 | invmat[0][0] = (mat_tmp[1][1] * mat_tmp[2][2] - mat_tmp[1][2] * mat_tmp[2][1]) * factor; 131 | invmat[0][1] = (mat_tmp[0][2] * mat_tmp[2][1] - mat_tmp[0][1] * mat_tmp[2][2]) * factor; 132 | invmat[0][2] = (mat_tmp[0][1] * mat_tmp[1][2] - mat_tmp[0][2] * mat_tmp[1][1]) * factor; 133 | 134 | invmat[1][0] = (mat_tmp[1][2] * mat_tmp[2][0] - mat_tmp[1][0] * mat_tmp[2][2]) * factor; 135 | invmat[1][1] = (mat_tmp[0][0] * mat_tmp[2][2] - mat_tmp[0][2] * mat_tmp[2][0]) * factor; 136 | invmat[1][2] = (mat_tmp[0][2] * mat_tmp[1][0] - mat_tmp[0][0] * mat_tmp[1][2]) * factor; 137 | 138 | invmat[2][0] = (mat_tmp[1][0] * mat_tmp[2][1] - mat_tmp[1][1] * mat_tmp[2][0]) * factor; 139 | invmat[2][1] = (mat_tmp[0][1] * mat_tmp[2][0] - mat_tmp[0][0] * mat_tmp[2][1]) * factor; 140 | invmat[2][2] = (mat_tmp[0][0] * mat_tmp[1][1] - mat_tmp[0][1] * mat_tmp[1][0]) * factor; 141 | } 142 | 143 | inline void invmat3_i(int invmat[3][3], int mat[3][3]) 144 | { 145 | int det; 146 | 147 | det = mat[0][0] * mat[1][1] * mat[2][2] 148 | + mat[1][0] * mat[2][1] * mat[0][2] 149 | + mat[2][0] * mat[0][1] * mat[1][2] 150 | - mat[0][0] * mat[2][1] * mat[1][2] 151 | - mat[2][0] * mat[1][1] * mat[0][2] 152 | - mat[1][0] * mat[0][1] * mat[2][2]; 153 | 154 | if(std::abs(det) == 0) { 155 | std::cout << "invmat3_i: Given matrix is singular" << std::endl; 156 | exit(1); 157 | } 158 | 159 | invmat[0][0] = (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) / det; 160 | invmat[0][1] = (mat[0][2] * mat[2][1] - mat[0][1] * mat[2][2]) / det; 161 | invmat[0][2] = (mat[0][1] * mat[1][2] - mat[0][2] * mat[1][1]) / det; 162 | 163 | invmat[1][0] = (mat[1][2] * mat[2][0] - mat[1][0] * mat[2][2]) / det; 164 | invmat[1][1] = (mat[0][0] * mat[2][2] - mat[0][2] * mat[2][0]) / det; 165 | invmat[1][2] = (mat[0][2] * mat[1][0] - mat[0][0] * mat[1][2]) / det; 166 | 167 | invmat[2][0] = (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]) / det; 168 | invmat[2][1] = (mat[0][1] * mat[2][0] - mat[0][0] * mat[2][1]) / det; 169 | invmat[2][2] = (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]) / det; 170 | 171 | } 172 | 173 | inline int nint(double x) 174 | { 175 | return int(x + 0.5 - (x < 0.0)); 176 | } 177 | 178 | template 179 | void insort(int n, T *arr) 180 | { 181 | int i, j; 182 | T tmp; 183 | 184 | for (i = 1; i < n; ++i) { 185 | tmp = arr[i]; 186 | for (j = i - 1; j >= 0 && arr[j] > tmp; --j) { 187 | arr[j + 1] = arr[j]; 188 | } 189 | arr[j + 1] = tmp; 190 | } 191 | } 192 | 193 | inline void sort_tail(const int n, int *arr) 194 | { 195 | int i, m; 196 | 197 | m = n - 1; 198 | int *ind_tmp; 199 | 200 | ind_tmp = new int[m]; 201 | 202 | for (i = 0; i < m; ++i) { 203 | ind_tmp[i] = arr[i + 1]; 204 | } 205 | 206 | insort(m, ind_tmp); 207 | 208 | for (i = 0; i < m; ++i) { 209 | arr[i + 1] = ind_tmp[i]; 210 | } 211 | delete [] ind_tmp; 212 | } 213 | -------------------------------------------------------------------------------- /src/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | memory.h 3 | 4 | Copyright (c) 2014, 2015, 2016 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | // memsize calculator 16 | 17 | namespace ALM_NS { 18 | inline size_t memsize_in_MB(const size_t size_of_one, 19 | const size_t n1) 20 | { 21 | const auto n = n1 * size_of_one; 22 | return n / 1000000; 23 | } 24 | 25 | inline size_t memsize_in_MB(const size_t size_of_one, 26 | const size_t n1, 27 | const size_t n2) 28 | { 29 | const auto n = n1 * n2 * size_of_one; 30 | return n / 1000000; 31 | } 32 | 33 | inline size_t memsize_in_MB(const size_t size_of_one, 34 | const size_t n1, 35 | const size_t n2, 36 | const size_t n3) 37 | { 38 | const auto n = n1 * n2 * n3 * size_of_one; 39 | return n / 1000000; 40 | } 41 | 42 | inline size_t memsize_in_MB(const size_t size_of_one, 43 | const size_t n1, 44 | const size_t n2, 45 | const size_t n3, 46 | const size_t n4) 47 | { 48 | const auto n = n1 * n2 * n3 * n4 * size_of_one; 49 | return n / 1000000; 50 | } 51 | 52 | // Declaration and definition must be located in the same file for template functions. 53 | 54 | /* allocator */ 55 | 56 | template 57 | T *allocate(T *&arr, 58 | const size_t n1) 59 | { 60 | try { 61 | arr = new T[n1]; 62 | } 63 | catch (std::bad_alloc &ba) { 64 | std::cout << " Caught an exception when trying to allocate 1-dimensional array" << std::endl; 65 | std::cout << " " << ba.what() << " : Array shape = " << n1 << std::endl; 66 | std::cout << " " << ba.what() << " : Array size (MB) = " << memsize_in_MB(sizeof(T), n1) << std::endl; 67 | std::exit(EXIT_FAILURE); 68 | } 69 | return arr; 70 | } 71 | 72 | template 73 | T **allocate(T **&arr, 74 | const size_t n1, 75 | const size_t n2) 76 | { 77 | try { 78 | arr = new T *[n1]; 79 | arr[0] = new T[n1 * n2]; 80 | for (size_t i = 1; i < n1; ++i) { 81 | arr[i] = arr[0] + i * n2; 82 | } 83 | } 84 | catch (std::bad_alloc &ba) { 85 | std::cout << " Caught an exception when trying to allocate 2-dimensional array" << std::endl; 86 | std::cout << " " << ba.what() << " : Array shape = " << n1 << "x" << n2 << std::endl; 87 | std::cout << " " << ba.what() << " : Array size (MB) = " << memsize_in_MB(sizeof(T), n1, n2) << std::endl; 88 | std::exit(EXIT_FAILURE); 89 | } 90 | return arr; 91 | } 92 | 93 | template 94 | T ***allocate(T ***&arr, 95 | const size_t n1, 96 | const size_t n2, 97 | const size_t n3) 98 | { 99 | try { 100 | arr = new T **[n1]; 101 | arr[0] = new T *[n1 * n2]; 102 | arr[0][0] = new T[n1 * n2 * n3]; 103 | for (size_t i = 0; i < n1; ++i) { 104 | arr[i] = arr[0] + i * n2; 105 | for (size_t j = 0; j < n2; ++j) { 106 | arr[i][j] = arr[0][0] + i * n2 * n3 + j * n3; 107 | } 108 | } 109 | } 110 | catch (std::bad_alloc &ba) { 111 | std::cout << " Caught an exception when trying to allocate 3-dimensional array" << std::endl; 112 | std::cout << " " << ba.what() << " : Array shape = " << n1 << "x" << n2 << "x" << n3 << std::endl; 113 | std::cout << " " << ba.what() << " : Array size (MB) = " << memsize_in_MB(sizeof(T), n1, n2, n3) << std:: 114 | endl; 115 | std::exit(EXIT_FAILURE); 116 | } 117 | return arr; 118 | } 119 | 120 | template 121 | T ****allocate(T ****&arr, 122 | const size_t n1, 123 | const size_t n2, 124 | const size_t n3, 125 | const size_t n4) 126 | { 127 | try { 128 | arr = new T ***[n1]; 129 | arr[0] = new T **[n1 * n2]; 130 | arr[0][0] = new T *[n1 * n2 * n3]; 131 | arr[0][0][0] = new T[n1 * n2 * n3 * n4]; 132 | 133 | for (size_t i = 0; i < n1; ++i) { 134 | arr[i] = arr[0] + i * n2; 135 | for (size_t j = 0; j < n2; ++j) { 136 | arr[i][j] = arr[0][0] + i * n2 * n3 + j * n3; 137 | for (size_t k = 0; k < n3; ++k) { 138 | arr[i][j][k] = arr[0][0][0] + i * n2 * n3 * n4 + j * n3 * n4 + k * n4; 139 | } 140 | } 141 | } 142 | } 143 | catch (std::bad_alloc &ba) { 144 | std::cout << " Caught an exception when trying to allocate 4-dimensional array" << std::endl; 145 | std::cout << " " << ba.what() << " : Array shape = " << n1 << "x" << n2 << "x" << n3 << "x" << n4 << std:: 146 | endl; 147 | std::cout << " " << ba.what() << " : Array size (MB) = " << memsize_in_MB(sizeof(T), n1, n2, n3, n4) << std 148 | :: 149 | endl; 150 | std::exit(EXIT_FAILURE); 151 | } 152 | return arr; 153 | } 154 | 155 | 156 | /* deallocator */ 157 | 158 | 159 | template 160 | void deallocate(T *&arr) 161 | { 162 | delete[] arr; 163 | arr = nullptr; 164 | } 165 | 166 | template 167 | void deallocate(T **&arr) 168 | { 169 | delete[] arr[0]; 170 | delete[] arr; 171 | arr = nullptr; 172 | } 173 | 174 | template 175 | void deallocate(T ***&arr) 176 | { 177 | delete[] arr[0][0]; 178 | delete[] arr[0]; 179 | delete[] arr; 180 | arr = nullptr; 181 | } 182 | 183 | template 184 | void deallocate(T ****&arr) 185 | { 186 | delete[] arr[0][0][0]; 187 | delete[] arr[0][0]; 188 | delete[] arr[0]; 189 | delete[] arr; 190 | arr = nullptr; 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /src/patterndisp.h: -------------------------------------------------------------------------------- 1 | /* 2 | patterndisp.h 3 | 4 | Copyright (c) 2014 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | //#include "pointers.h" 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "cluster.h" 19 | #include "symmetry.h" 20 | #include "fcs.h" 21 | #include "constraint.h" 22 | #include "system.h" 23 | 24 | namespace ALM_NS { 25 | class DispAtomSet { 26 | public: 27 | std::vector atomset; 28 | 29 | DispAtomSet(); 30 | 31 | DispAtomSet(std::vector atomset_in) : atomset(std::move(atomset_in)) {} 32 | }; 33 | 34 | class DirectionVec { 35 | public: 36 | double direction[3]{}; 37 | 38 | DirectionVec(); 39 | 40 | DirectionVec(const double vec_in[3]) 41 | { 42 | for (auto i = 0; i < 3; ++i) direction[i] = vec_in[i]; 43 | } 44 | }; 45 | 46 | class DispDirectionHarmonic { 47 | public: 48 | int atom; 49 | std::vector directionlist; 50 | 51 | DispDirectionHarmonic(); 52 | 53 | DispDirectionHarmonic(const int n, 54 | const std::vector &list_in) 55 | { 56 | atom = n; 57 | for (auto &it: list_in) { 58 | directionlist.push_back(it); 59 | } 60 | } 61 | }; 62 | 63 | class AtomWithDirection { 64 | public: 65 | std::vector atoms; 66 | std::vector directions; 67 | 68 | AtomWithDirection(); 69 | 70 | AtomWithDirection(std::vector a, 71 | std::vector b) : atoms(std::move(a)), directions(std::move(b)) {} 72 | 73 | AtomWithDirection(const int n, 74 | const int *a, 75 | const double **b) 76 | { 77 | for (auto i = 0; i < n; ++i) { 78 | atoms.push_back(a[i]); 79 | for (auto j = 0; j < 3; ++j) { 80 | directions.push_back(b[i][j]); 81 | } 82 | } 83 | } 84 | }; 85 | 86 | 87 | inline bool operator<(const DispAtomSet &a, 88 | const DispAtomSet &b) 89 | { 90 | return std::lexicographical_compare(a.atomset.begin(), a.atomset.end(), 91 | b.atomset.begin(), b.atomset.end()); 92 | } 93 | 94 | 95 | class IndexWithSign { 96 | public: 97 | int ind, sign; 98 | 99 | IndexWithSign(); 100 | 101 | IndexWithSign(const int ind_in, 102 | const int sign_in) 103 | { 104 | ind = ind_in; 105 | sign = sign_in; 106 | } 107 | }; 108 | 109 | inline bool operator<(const IndexWithSign &a, 110 | const IndexWithSign &b) 111 | { 112 | return a.ind < b.ind; 113 | } 114 | 115 | class Displace { 116 | public: 117 | Displace(); 118 | 119 | ~Displace(); 120 | 121 | void gen_displacement_pattern(const Cluster *cluster, 122 | const Symmetry *symmetry, 123 | const Fcs *fcs, 124 | const Constraint *constraint, 125 | const System *system, 126 | const int verbosity); 127 | 128 | void set_trim_dispsign_for_evenfunc(const bool); 129 | 130 | std::string get_disp_basis() const; 131 | 132 | void set_disp_basis(const std::string); 133 | 134 | const std::vector &get_pattern_all(const int) const; 135 | 136 | private: 137 | bool trim_dispsign_for_evenfunc; 138 | std::string disp_basis; 139 | std::vector *pattern_all; 140 | 141 | std::vector disp_harm, disp_harm_best; 142 | 143 | void set_default_variables(); 144 | 145 | void deallocate_variables(); 146 | 147 | void generate_pattern_all(const int maxorder, 148 | const size_t nat, 149 | const double lavec[3][3], 150 | const Symmetry *symmetry, 151 | const std::set *dispset_in, 152 | const std::string preferred_basis) const; 153 | 154 | void generate_signvecs(const int, 155 | std::vector> &, 156 | std::vector) const; 157 | 158 | void find_unique_sign_pairs(const int natom_disp_in, 159 | const size_t nat, 160 | const Symmetry *symmetry, 161 | const std::vector> sign_in, 162 | const std::vector &pair_in, 163 | std::vector> &sign_out, 164 | const std::string preferred_basis) const; 165 | }; 166 | } 167 | -------------------------------------------------------------------------------- /src/rref.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fcs.h" 4 | 5 | void rref(const size_t nrows, 6 | const size_t ncols, 7 | double **mat, 8 | size_t &nrank, 9 | const double tolerance = 1.0e-12); 10 | 11 | void rref(std::vector> &mat, 12 | const double tolerance = 1.0e-12); 13 | 14 | void rref_sparse(const size_t ncols, 15 | ConstraintSparseForm &sp_constraint, 16 | const double tolerance = 1.0e-12); 17 | -------------------------------------------------------------------------------- /src/symmetry.h: -------------------------------------------------------------------------------- 1 | /* 2 | symmetry.h 3 | 4 | Copyright (c) 2014, 2015, 2016 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include "system.h" 16 | #include "timer.h" 17 | 18 | namespace ALM_NS { 19 | class SymmetryOperation { 20 | public: 21 | int rotation[3][3]; // in lattice basis 22 | double tran[3]; // in Cartesian basis 23 | double rotation_cart[3][3]; // in Cartesian basis 24 | bool compatible_with_lattice; 25 | bool compatible_with_cartesian; 26 | bool is_translation; 27 | 28 | SymmetryOperation(); 29 | 30 | SymmetryOperation(const int rot_in[3][3], 31 | const double tran_in[3], 32 | const double rot_cart_in[3][3], 33 | const bool compatibility_lat, 34 | const bool compatibility_cart, 35 | const bool is_trans_in) 36 | { 37 | for (auto i = 0; i < 3; ++i) { 38 | for (auto j = 0; j < 3; ++j) { 39 | rotation[i][j] = rot_in[i][j]; 40 | rotation_cart[i][j] = rot_cart_in[i][j]; 41 | } 42 | } 43 | for (auto i = 0; i < 3; ++i) { 44 | tran[i] = tran_in[i]; 45 | } 46 | compatible_with_lattice = compatibility_lat; 47 | compatible_with_cartesian = compatibility_cart; 48 | is_translation = is_trans_in; 49 | } 50 | 51 | // Operator definition to sort 52 | bool operator<(const SymmetryOperation &a) const 53 | { 54 | std::vector v1, v2; 55 | for (auto i = 0; i < 3; ++i) { 56 | for (auto j = 0; j < 3; ++j) { 57 | v1.push_back(static_cast(rotation[i][j])); 58 | v2.push_back(static_cast(a.rotation[i][j])); 59 | } 60 | } 61 | for (auto i = 0; i < 3; ++i) { 62 | if (tran[i] < 0.0) { 63 | v1.push_back(1.0 + tran[i]); 64 | } else { 65 | v1.push_back(tran[i]); 66 | } 67 | if (a.tran[i] < 0.0) { 68 | v2.push_back(1.0 + a.tran[i]); 69 | } else { 70 | v2.push_back(a.tran[i]); 71 | } 72 | } 73 | return std::lexicographical_compare(v1.begin(), v1.end(), 74 | v2.begin(), v2.end()); 75 | } 76 | }; 77 | 78 | class RotationMatrix { 79 | public: 80 | int mat[3][3]; 81 | 82 | RotationMatrix(); 83 | 84 | RotationMatrix(const int rot[3][3]) 85 | { 86 | for (auto i = 0; i < 3; ++i) { 87 | for (auto j = 0; j < 3; ++j) { 88 | mat[i][j] = rot[i][j]; 89 | } 90 | } 91 | } 92 | }; 93 | 94 | class Maps { 95 | public: 96 | int atom_num; 97 | int tran_num; 98 | }; 99 | 100 | class Symmetry { 101 | public: 102 | Symmetry(); 103 | 104 | ~Symmetry(); 105 | 106 | void init(const System *system, 107 | const int verbosity, 108 | Timer *timer); 109 | 110 | double get_tolerance() const; 111 | 112 | void set_tolerance(const double); 113 | 114 | int get_print_symmetry() const; 115 | 116 | void set_print_symmetry(const int); 117 | 118 | const std::vector &get_map_s2p() const; 119 | 120 | const std::vector> &get_map_p2s() const; 121 | 122 | const std::vector &get_SymmData() const; 123 | 124 | const std::vector> &get_map_sym() const; 125 | 126 | const std::vector &get_symnum_tran() const; 127 | 128 | size_t get_nsym() const; 129 | 130 | size_t get_ntran() const; 131 | 132 | size_t get_nat_prim() const; 133 | 134 | private: 135 | size_t nsym, ntran, nat_prim; 136 | std::vector> map_sym; // [nat, nsym] 137 | std::vector> map_p2s; // [nat_prim, ntran] 138 | std::vector map_s2p; // [nat] 139 | std::vector SymmData; // [nsym] 140 | std::vector symnum_tran; // [ntran] 141 | 142 | double tolerance; 143 | bool use_internal_symm_finder; 144 | int printsymmetry; 145 | 146 | void set_default_variables(); 147 | 148 | void deallocate_variables(); 149 | 150 | void setup_symmetry_operation(const Cell &, 151 | const int [3], 152 | const std::vector> &, 153 | const Spin &, 154 | const int); 155 | 156 | void gen_mapping_information(const Cell &, 157 | const std::vector> &); 158 | 159 | void findsym_alm(const Cell &, 160 | const int [3], 161 | const std::vector> &, 162 | const Spin &); 163 | 164 | int findsym_spglib(const Cell &, 165 | const std::vector> &, 166 | const Spin &, 167 | std::string &); 168 | 169 | bool is_translation(const int [3][3]) const; 170 | 171 | bool is_proper(const double [3][3]) const; 172 | 173 | void symop_in_cart(double [3][3], 174 | const int [3][3], 175 | const double [3][3], 176 | const double [3][3]) const; 177 | 178 | void print_symminfo_stdout() const; 179 | 180 | template 181 | bool is_compatible(const T [3][3], 182 | double tolerance_zero = 1.0e-5); 183 | 184 | void find_lattice_symmetry(const double [3][3], 185 | std::vector &) const; 186 | 187 | void find_crystal_symmetry(const Cell &, 188 | const std::vector> &, 189 | const int [3], 190 | const Spin &, 191 | const std::vector &); 192 | 193 | void set_primitive_lattice(const double aa[3][3], 194 | const size_t nat, 195 | const int *kd, 196 | double **x, 197 | double aa_prim[3][3], 198 | size_t &nat_prim, 199 | int *kd_prim, 200 | double **x_prim, 201 | const double symprec) const; 202 | 203 | std::string file_sym; 204 | }; 205 | } 206 | -------------------------------------------------------------------------------- /src/system.h: -------------------------------------------------------------------------------- 1 | /* 2 | system.h 3 | 4 | Copyright (c) 2014 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include "timer.h" 16 | 17 | namespace ALM_NS { 18 | class AtomType { 19 | public: 20 | int element; 21 | double magmom; 22 | 23 | bool operator<(const AtomType &a) const 24 | { 25 | if (this->element < a.element) { 26 | return true; 27 | } 28 | if (this->element == a.element) { 29 | return this->magmom < a.magmom; 30 | } 31 | return false; 32 | } 33 | }; 34 | 35 | class Cell { 36 | public: 37 | double lattice_vector[3][3]; 38 | double reciprocal_lattice_vector[3][3]; 39 | double volume; 40 | size_t number_of_atoms; 41 | size_t number_of_elems; 42 | std::vector kind; 43 | std::vector> x_fractional; 44 | std::vector> x_cartesian; 45 | }; 46 | 47 | class Spin { 48 | public: 49 | bool lspin; 50 | int time_reversal_symm; 51 | int noncollinear; 52 | std::vector> magmom; 53 | }; 54 | 55 | class System { 56 | public: 57 | System(); 58 | 59 | ~System(); 60 | 61 | void init(const int, 62 | Timer *); 63 | 64 | void frac2cart(double **) const; 65 | 66 | void set_supercell(const double [3][3], 67 | const size_t, 68 | const int *, 69 | const double [][3]); 70 | 71 | void set_kdname(const std::string *); 72 | 73 | void set_periodicity(const int [3]); 74 | 75 | void set_spin_variables(const size_t nat, 76 | const bool, 77 | const int, 78 | const int, 79 | const double (*)[3]); 80 | 81 | void set_str_magmom(std::string); 82 | 83 | const Cell &get_supercell() const; 84 | 85 | double ***get_x_image() const; 86 | 87 | int *get_exist_image() const; 88 | 89 | std::string *get_kdname() const; 90 | 91 | int *get_periodicity() const; 92 | 93 | const Spin &get_spin() const; 94 | 95 | const std::string &get_str_magmom() const; 96 | 97 | const std::vector> &get_atomtype_group() const; 98 | 99 | private: 100 | // Variables for geometric structure 101 | Cell supercell; 102 | std::string *kdname; 103 | int *is_periodic; // is_periodic[3]; 104 | double ***x_image; 105 | int *exist_image; 106 | 107 | // Variables for spins 108 | Spin spin; 109 | std::string str_magmom; 110 | 111 | // concatenate atomic kind and magmom (only for collinear case) 112 | std::vector> atomtype_group; 113 | 114 | enum LatticeType { 115 | Direct, Reciprocal 116 | }; 117 | 118 | void set_reciprocal_latt(const double [3][3], 119 | double [3][3]) const; 120 | 121 | void set_default_variables(); 122 | 123 | void deallocate_variables(); 124 | 125 | double volume(const double [3][3], 126 | LatticeType) const; 127 | 128 | void set_atomtype_group(); 129 | 130 | void generate_coordinate_of_periodic_images(); 131 | 132 | void print_structure_stdout(const Cell &); 133 | 134 | void print_magmom_stdout() const; 135 | }; 136 | } 137 | -------------------------------------------------------------------------------- /src/timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | timer.cpp 3 | 4 | Copyright (c) 2014, 2015, 2016 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #include "timer.h" 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace ALM_NS; 17 | 18 | Timer::Timer() 19 | { 20 | #if defined(WIN32) || defined(_WIN32) 21 | QueryPerformanceCounter(&walltime_ref); 22 | QueryPerformanceFrequency(&frequency); 23 | cputime_ref = get_cputime(); 24 | #else 25 | gettimeofday(&walltime_ref, nullptr); 26 | cputime_ref = static_cast(clock()); 27 | #endif 28 | lock = false; 29 | } 30 | 31 | Timer::~Timer() 32 | { 33 | walltime.clear(); 34 | cputime.clear(); 35 | } 36 | 37 | void Timer::reset() 38 | { 39 | #if defined(WIN32) || defined(_WIN32) 40 | QueryPerformanceCounter(&walltime_ref); 41 | #else 42 | gettimeofday(&walltime_ref, nullptr); 43 | #endif 44 | } 45 | 46 | double Timer::elapsed_walltime() const 47 | { 48 | #if defined(WIN32) || defined(_WIN32) 49 | LARGE_INTEGER time_now; 50 | QueryPerformanceCounter(&time_now); 51 | return static_cast(time_now.QuadPart - walltime_ref.QuadPart) 52 | / static_cast(frequency.QuadPart); 53 | #else 54 | timeval time_now; 55 | gettimeofday(&time_now, nullptr); 56 | return (time_now.tv_sec - walltime_ref.tv_sec) 57 | + (time_now.tv_usec - walltime_ref.tv_usec) * 1.0e-6; 58 | #endif 59 | } 60 | 61 | #if defined(WIN32) || defined(_WIN32) 62 | double Timer::get_cputime() const 63 | { 64 | FILETIME createTime; 65 | FILETIME exitTime; 66 | FILETIME kernelTime; 67 | FILETIME userTime; 68 | if (GetProcessTimes(GetCurrentProcess(), 69 | &createTime, &exitTime, &kernelTime, &userTime) != -1) { 70 | SYSTEMTIME userSystemTime; 71 | if (FileTimeToSystemTime(&userTime, &userSystemTime) != -1) 72 | return static_cast(userSystemTime.wHour) * 3600.0 + 73 | static_cast(userSystemTime.wMinute) * 60.0 + 74 | static_cast(userSystemTime.wSecond) + 75 | static_cast(userSystemTime.wMilliseconds) / 1000.0; 76 | } 77 | return 0.0; 78 | } 79 | #endif 80 | 81 | double Timer::elapsed_cputime() const 82 | { 83 | #if defined(WIN32) || defined(_WIN32) 84 | return get_cputime() - cputime_ref; 85 | #else 86 | return (static_cast(clock()) - cputime_ref) / CLOCKS_PER_SEC; 87 | #endif 88 | } 89 | 90 | void Timer::print_elapsed() const 91 | { 92 | std::cout << " Time Elapsed: " << elapsed_walltime() << " sec." 93 | << std::endl << std::endl; 94 | } 95 | 96 | 97 | std::string Timer::DateAndTime() 98 | { 99 | time_t current; 100 | std::time(¤t); 101 | 102 | #if defined(WIN32) || defined(_WIN32) 103 | struct tm local{}; 104 | char str_now[32]; 105 | 106 | auto err_t = localtime_s(&local, ¤t); 107 | err_t = asctime_s(str_now, 32, &local); 108 | return str_now; 109 | #else 110 | struct tm *local; 111 | local = std::localtime(¤t); 112 | 113 | return asctime(local); 114 | #endif 115 | } 116 | 117 | 118 | void Timer::start_clock(const std::string str_tag) 119 | { 120 | if (lock) { 121 | std::cout << "Error: cannot start clock because it's occupied." << std::endl; 122 | exit(1); 123 | } 124 | // Initialize the counter if the key is new 125 | if (walltime.find(str_tag) == walltime.end()) { 126 | walltime[str_tag] = 0.0; 127 | } 128 | if (cputime.find(str_tag) == cputime.end()) { 129 | cputime[str_tag] = 0.0; 130 | } 131 | 132 | wtime_tmp = elapsed_walltime(); 133 | ctime_tmp = elapsed_cputime(); 134 | 135 | lock = true; 136 | } 137 | 138 | void Timer::stop_clock(const std::string str_tag) 139 | { 140 | if (!lock) { 141 | std::cout << "Error: cannot stop clock because it's not initialized." << std::endl; 142 | exit(1); 143 | } 144 | 145 | auto it = walltime.find(str_tag); 146 | 147 | if (it == walltime.end()) { 148 | std::cout << "Error: invalid tag for clock" << std::endl; 149 | exit(1); 150 | } 151 | 152 | auto time_tmp = (*it).second; 153 | time_tmp += elapsed_walltime() - wtime_tmp; 154 | walltime[str_tag] = time_tmp; 155 | 156 | it = cputime.find(str_tag); 157 | if (it == cputime.end()) { 158 | std::cout << "Error: invalid tag for clock" << std::endl; 159 | exit(1); 160 | } 161 | 162 | time_tmp = (*it).second; 163 | time_tmp += elapsed_cputime() - ctime_tmp; 164 | cputime[str_tag] = time_tmp; 165 | 166 | lock = false; 167 | } 168 | 169 | double Timer::get_walltime(const std::string str_tag) 170 | { 171 | const auto it = walltime.find(str_tag); 172 | 173 | if (it == walltime.end()) { 174 | std::cout << "Error: invalid tag for clock" << std::endl; 175 | exit(1); 176 | } 177 | return (*it).second; 178 | } 179 | 180 | 181 | double Timer::get_cputime(const std::string str_tag) 182 | { 183 | const auto it = cputime.find(str_tag); 184 | 185 | if (it == cputime.end()) { 186 | std::cout << "Error: invalid tag for clock" << std::endl; 187 | exit(1); 188 | } 189 | return (*it).second; 190 | } 191 | -------------------------------------------------------------------------------- /src/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | timer.h 3 | 4 | Copyright (c) 2014 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | #if defined(WIN32) || defined(_WIN32) 17 | #include 18 | #else 19 | 20 | #include 21 | #include 22 | 23 | #endif 24 | 25 | namespace ALM_NS { 26 | class Timer { 27 | public: 28 | Timer(); 29 | 30 | ~Timer(); 31 | 32 | void print_elapsed() const; 33 | 34 | void start_clock(std::string); 35 | 36 | void stop_clock(std::string); 37 | 38 | double get_walltime(std::string); 39 | 40 | double get_cputime(std::string); 41 | 42 | static std::string DateAndTime(); 43 | 44 | private: 45 | void reset(); 46 | 47 | double elapsed_walltime() const; 48 | 49 | double elapsed_cputime() const; 50 | 51 | std::map walltime; 52 | std::map cputime; 53 | double wtime_tmp, ctime_tmp; 54 | bool lock; 55 | 56 | #if defined(WIN32) || defined(_WIN32) 57 | LARGE_INTEGER walltime_ref; 58 | LARGE_INTEGER frequency; 59 | double get_cputime() const; 60 | double cputime_ref; 61 | #else 62 | timeval walltime_ref; 63 | double cputime_ref; 64 | #endif 65 | }; 66 | } 67 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | version.h 3 | 4 | Copyright (c) 2016 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | static const std::string ALAMODE_VERSION = "2.0.0 Dev"; 16 | -------------------------------------------------------------------------------- /src/writer.h: -------------------------------------------------------------------------------- 1 | /* 2 | writer.h 3 | 4 | Copyright (c) 2014, 2015, 2016 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | #include "system.h" 17 | #include "symmetry.h" 18 | #include "cluster.h" 19 | #include "patterndisp.h" 20 | #include "fcs.h" 21 | #include "constraint.h" 22 | #include "optimize.h" 23 | #include "files.h" 24 | 25 | 26 | namespace ALM_NS { 27 | class AtomProperty { 28 | public: 29 | double x, y, z; 30 | int kind; 31 | size_t atom, tran; 32 | 33 | AtomProperty() = default;; 34 | 35 | AtomProperty(const AtomProperty &other) = default; 36 | 37 | AtomProperty(const double *pos, 38 | const int kind_in, 39 | const int atom_in, 40 | const int tran_in) 41 | { 42 | x = pos[0]; 43 | y = pos[1]; 44 | z = pos[2]; 45 | kind = kind_in; 46 | atom = atom_in; 47 | tran = tran_in; 48 | } 49 | }; 50 | 51 | class SystemInfo { 52 | public: 53 | double lattice_vector[3][3]; 54 | std::vector atoms; 55 | size_t nat, natmin, ntran; 56 | size_t nspecies; 57 | 58 | SystemInfo() = default;; 59 | }; 60 | 61 | class Writer { 62 | public: 63 | Writer(); 64 | 65 | ~Writer(); 66 | 67 | void writeall(const System *system, 68 | const Symmetry *symmetry, 69 | const Cluster *cluster, 70 | const Constraint *constraint, 71 | const Fcs *fcs, 72 | const Optimize *optimize, 73 | const Files *files, 74 | const int verbosity) const; 75 | 76 | void write_input_vars(const System *system, 77 | const Symmetry *symmetry, 78 | const Cluster *cluster, 79 | const Displace *displace, 80 | const Fcs *fcs, 81 | const Constraint *constraint, 82 | const Optimize *optimize, 83 | const Files *files, 84 | const std::string run_mode) const; 85 | 86 | void write_displacement_pattern(const Cluster *cluster, 87 | const Displace *displace, 88 | const std::string prefix, 89 | const int verbosity) const; 90 | 91 | void save_fcs_with_specific_format(const std::string fcs_format, 92 | const System *system, 93 | const Symmetry *symmetry, 94 | const Cluster *cluster, 95 | const Constraint *constraint, 96 | const Fcs *fcs, 97 | const Optimize *optimize, 98 | const Files *files, 99 | const int verbosity) const; 100 | 101 | void set_fcs_save_flag(const std::string key_str, const int val); 102 | 103 | int get_fcs_save_flag(const std::string key_str); 104 | 105 | void set_filename_fcs(const std::string filename_in); 106 | 107 | std::string get_filename_fcs() const; 108 | 109 | void set_output_maxorder(const int maxorder); 110 | 111 | int get_output_maxorder() const; 112 | 113 | private: 114 | void write_force_constants(const Cluster *cluster, 115 | const Fcs *fcs, 116 | const Symmetry *symmetry, 117 | const double *fcs_vals, 118 | const int verbosity, 119 | const std::string fname_save) const; 120 | 121 | void save_fcs_alamode_oldformat(const System *system, 122 | const Symmetry *symmetry, 123 | const Cluster *cluster, 124 | const Fcs *fcs, 125 | const Constraint *constraint, 126 | const double *fcs_vals, 127 | const std::string fname_dfset, 128 | const std::string fname_fcs, 129 | const int verbosity) const; 130 | 131 | void write_hessian(const System *system, 132 | const Symmetry *symmetry, 133 | const Fcs *fcs, 134 | const std::string fname_out, 135 | const int verbosity) const; 136 | 137 | void save_fc2_QEfc_format(const System *system, 138 | const Symmetry *symmetry, 139 | const Fcs *fcs, 140 | const std::string fname_out, 141 | const int verbosity) const; 142 | 143 | void save_fc3_thirdorderpy_format(const System *system, 144 | const Symmetry *symmetry, 145 | const Cluster *cluster, 146 | const Constraint *constraint, 147 | const Fcs *fcs, 148 | const std::string fname_out, 149 | const int verbosity) const; 150 | 151 | std::string easyvizint(int) const; 152 | 153 | std::string double2string(double, 154 | int nprec = 15) const; 155 | 156 | std::map save_format_flags; 157 | int output_maxorder; 158 | std::string file_fcs, file_hes; 159 | std::string filename_fcs; 160 | }; 161 | } 162 | -------------------------------------------------------------------------------- /src/xml_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | xml_parser.h 3 | 4 | Copyright (c) 2014 Terumasa Tadano 5 | 6 | This file is distributed under the terms of the MIT license. 7 | Please see the file 'LICENCE.txt' in the root directory 8 | or http://opensource.org/licenses/mit-license.php for information. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | inline std::string 19 | get_value_from_xml(const boost::property_tree::ptree &pt_in, std::string str, const int exit_when_error = 1) 20 | { 21 | if (boost::optional str_entry = pt_in.get_optional(str)) { 22 | return str_entry.get(); 23 | } else { 24 | if (exit_when_error) { 25 | std::cout << " Error in get_value_from_xml" << std::endl; 26 | std::cout << " The following entry could not be found in the XML file : " 27 | << str << std::endl; 28 | exit(EXIT_FAILURE); 29 | } else { 30 | return ""; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/SiC_fitting.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | import numpy as np 5 | from alm import ALM 6 | 7 | 8 | lavec = np.loadtxt('lavec.dat') 9 | xcoord = np.loadtxt('xcoord.dat') 10 | kd = np.loadtxt('kd.dat') 11 | force = np.loadtxt("sic_force.dat").reshape((-1, 64, 3)) 12 | disp = np.loadtxt("sic_disp.dat").reshape((-1, 64, 3)) 13 | 14 | 15 | # alm.alm_new() and alm.alm_delete() are done by 'with' statement 16 | with ALM(lavec, xcoord, kd) as alm: 17 | alm.define(2) 18 | alm.set_displacement_and_force(disp, force+5e-4*np.random.random(force.shape)) 19 | alm.set_verbosity(1) 20 | info = alm.optimize(solver='dense') 21 | 22 | fc_values, elem_indices = alm.get_fc(1) # harmonic fc 23 | print('RMS FC2: %.4f' % np.sqrt((fc_values**2).mean())) 24 | fc_values, elem_indices = alm.get_fc(2) # cubic fc 25 | print('RMS FC3: %.4f' % np.sqrt((fc_values**2).mean())) 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /test/Si_fitting.py: -------------------------------------------------------------------------------- 1 | # 2 | # Si_fitting2.py 3 | # 4 | # This is an example to run ALM in the fitting mode. 5 | # 6 | 7 | from alm import ALM 8 | import numpy as np 9 | 10 | lavec = [[20.406, 0, 0], 11 | [0, 20.406, 0], 12 | [0, 0, 20.406]] 13 | xcoord = [[ 0.0000000000000000, 0.0000000000000000, 0.0000000000000000], 14 | [ 0.0000000000000000, 0.0000000000000000, 0.5000000000000000], 15 | [ 0.0000000000000000, 0.2500000000000000, 0.2500000000000000], 16 | [ 0.0000000000000000, 0.2500000000000000, 0.7500000000000000], 17 | [ 0.0000000000000000, 0.5000000000000000, 0.0000000000000000], 18 | [ 0.0000000000000000, 0.5000000000000000, 0.5000000000000000], 19 | [ 0.0000000000000000, 0.7500000000000000, 0.2500000000000000], 20 | [ 0.0000000000000000, 0.7500000000000000, 0.7500000000000000], 21 | [ 0.1250000000000000, 0.1250000000000000, 0.1250000000000000], 22 | [ 0.1250000000000000, 0.1250000000000000, 0.6250000000000000], 23 | [ 0.1250000000000000, 0.3750000000000000, 0.3750000000000000], 24 | [ 0.1250000000000000, 0.3750000000000000, 0.8750000000000000], 25 | [ 0.1250000000000000, 0.6250000000000000, 0.1250000000000000], 26 | [ 0.1250000000000000, 0.6250000000000000, 0.6250000000000000], 27 | [ 0.1250000000000000, 0.8750000000000000, 0.3750000000000000], 28 | [ 0.1250000000000000, 0.8750000000000000, 0.8750000000000000], 29 | [ 0.2500000000000000, 0.0000000000000000, 0.2500000000000000], 30 | [ 0.2500000000000000, 0.0000000000000000, 0.7500000000000000], 31 | [ 0.2500000000000000, 0.2500000000000000, 0.0000000000000000], 32 | [ 0.2500000000000000, 0.2500000000000000, 0.5000000000000000], 33 | [ 0.2500000000000000, 0.5000000000000000, 0.2500000000000000], 34 | [ 0.2500000000000000, 0.5000000000000000, 0.7500000000000000], 35 | [ 0.2500000000000000, 0.7500000000000000, 0.0000000000000000], 36 | [ 0.2500000000000000, 0.7500000000000000, 0.5000000000000000], 37 | [ 0.3750000000000000, 0.1250000000000000, 0.3750000000000000], 38 | [ 0.3750000000000000, 0.1250000000000000, 0.8750000000000000], 39 | [ 0.3750000000000000, 0.3750000000000000, 0.1250000000000000], 40 | [ 0.3750000000000000, 0.3750000000000000, 0.6250000000000000], 41 | [ 0.3750000000000000, 0.6250000000000000, 0.3750000000000000], 42 | [ 0.3750000000000000, 0.6250000000000000, 0.8750000000000000], 43 | [ 0.3750000000000000, 0.8750000000000000, 0.1250000000000000], 44 | [ 0.3750000000000000, 0.8750000000000000, 0.6250000000000000], 45 | [ 0.5000000000000000, 0.0000000000000000, 0.0000000000000000], 46 | [ 0.5000000000000000, 0.0000000000000000, 0.5000000000000000], 47 | [ 0.5000000000000000, 0.2500000000000000, 0.2500000000000000], 48 | [ 0.5000000000000000, 0.2500000000000000, 0.7500000000000000], 49 | [ 0.5000000000000000, 0.5000000000000000, 0.0000000000000000], 50 | [ 0.5000000000000000, 0.5000000000000000, 0.5000000000000000], 51 | [ 0.5000000000000000, 0.7500000000000000, 0.2500000000000000], 52 | [ 0.5000000000000000, 0.7500000000000000, 0.7500000000000000], 53 | [ 0.6250000000000000, 0.1250000000000000, 0.1250000000000000], 54 | [ 0.6250000000000000, 0.1250000000000000, 0.6250000000000000], 55 | [ 0.6250000000000000, 0.3750000000000000, 0.3750000000000000], 56 | [ 0.6250000000000000, 0.3750000000000000, 0.8750000000000000], 57 | [ 0.6250000000000000, 0.6250000000000000, 0.1250000000000000], 58 | [ 0.6250000000000000, 0.6250000000000000, 0.6250000000000000], 59 | [ 0.6250000000000000, 0.8750000000000000, 0.3750000000000000], 60 | [ 0.6250000000000000, 0.8750000000000000, 0.8750000000000000], 61 | [ 0.7500000000000000, 0.0000000000000000, 0.2500000000000000], 62 | [ 0.7500000000000000, 0.0000000000000000, 0.7500000000000000], 63 | [ 0.7500000000000000, 0.2500000000000000, 0.0000000000000000], 64 | [ 0.7500000000000000, 0.2500000000000000, 0.5000000000000000], 65 | [ 0.7500000000000000, 0.5000000000000000, 0.2500000000000000], 66 | [ 0.7500000000000000, 0.5000000000000000, 0.7500000000000000], 67 | [ 0.7500000000000000, 0.7500000000000000, 0.0000000000000000], 68 | [ 0.7500000000000000, 0.7500000000000000, 0.5000000000000000], 69 | [ 0.8750000000000000, 0.1250000000000000, 0.3750000000000000], 70 | [ 0.8750000000000000, 0.1250000000000000, 0.8750000000000000], 71 | [ 0.8750000000000000, 0.3750000000000000, 0.1250000000000000], 72 | [ 0.8750000000000000, 0.3750000000000000, 0.6250000000000000], 73 | [ 0.8750000000000000, 0.6250000000000000, 0.3750000000000000], 74 | [ 0.8750000000000000, 0.6250000000000000, 0.8750000000000000], 75 | [ 0.8750000000000000, 0.8750000000000000, 0.1250000000000000], 76 | [ 0.8750000000000000, 0.8750000000000000, 0.6250000000000000]] 77 | 78 | kd = [14] * 64 79 | 80 | force = np.loadtxt("si_force.dat").reshape((-1, 64, 3))[:22] 81 | disp = np.loadtxt("si_disp.dat").reshape((-1, 64, 3))[:22] 82 | 83 | # alm.alm_new() and alm.alm_delete() are done by 'with' statement 84 | with ALM(lavec, xcoord, kd) as alm: 85 | alm.define(2, [-1, 7.3]) 86 | alm.set_displacement_and_force(disp, force+5e-4*np.random.random(force.shape)) 87 | alm.set_verbosity(1) 88 | info = alm.optimize() 89 | 90 | c = "xyz" 91 | fc_values, elem_indices = alm.get_fc(1) # harmonic fc 92 | print('RMS FC2: %.4f' % np.sqrt((fc_values**2).mean())) 93 | fc_values, elem_indices = alm.get_fc(2) # cubic fc 94 | print('RMS FC3: %.4f' % np.sqrt((fc_values**2).mean())) 95 | 96 | -------------------------------------------------------------------------------- /test/kd.dat: -------------------------------------------------------------------------------- 1 | 6.000000000000000000e+00 2 | 6.000000000000000000e+00 3 | 6.000000000000000000e+00 4 | 6.000000000000000000e+00 5 | 6.000000000000000000e+00 6 | 6.000000000000000000e+00 7 | 6.000000000000000000e+00 8 | 6.000000000000000000e+00 9 | 6.000000000000000000e+00 10 | 6.000000000000000000e+00 11 | 6.000000000000000000e+00 12 | 6.000000000000000000e+00 13 | 6.000000000000000000e+00 14 | 6.000000000000000000e+00 15 | 6.000000000000000000e+00 16 | 6.000000000000000000e+00 17 | 6.000000000000000000e+00 18 | 6.000000000000000000e+00 19 | 6.000000000000000000e+00 20 | 6.000000000000000000e+00 21 | 6.000000000000000000e+00 22 | 6.000000000000000000e+00 23 | 6.000000000000000000e+00 24 | 6.000000000000000000e+00 25 | 6.000000000000000000e+00 26 | 6.000000000000000000e+00 27 | 6.000000000000000000e+00 28 | 6.000000000000000000e+00 29 | 6.000000000000000000e+00 30 | 6.000000000000000000e+00 31 | 6.000000000000000000e+00 32 | 6.000000000000000000e+00 33 | 1.400000000000000000e+01 34 | 1.400000000000000000e+01 35 | 1.400000000000000000e+01 36 | 1.400000000000000000e+01 37 | 1.400000000000000000e+01 38 | 1.400000000000000000e+01 39 | 1.400000000000000000e+01 40 | 1.400000000000000000e+01 41 | 1.400000000000000000e+01 42 | 1.400000000000000000e+01 43 | 1.400000000000000000e+01 44 | 1.400000000000000000e+01 45 | 1.400000000000000000e+01 46 | 1.400000000000000000e+01 47 | 1.400000000000000000e+01 48 | 1.400000000000000000e+01 49 | 1.400000000000000000e+01 50 | 1.400000000000000000e+01 51 | 1.400000000000000000e+01 52 | 1.400000000000000000e+01 53 | 1.400000000000000000e+01 54 | 1.400000000000000000e+01 55 | 1.400000000000000000e+01 56 | 1.400000000000000000e+01 57 | 1.400000000000000000e+01 58 | 1.400000000000000000e+01 59 | 1.400000000000000000e+01 60 | 1.400000000000000000e+01 61 | 1.400000000000000000e+01 62 | 1.400000000000000000e+01 63 | 1.400000000000000000e+01 64 | 1.400000000000000000e+01 65 | -------------------------------------------------------------------------------- /test/lavec.dat: -------------------------------------------------------------------------------- 1 | 8.743057892980546697e+00 0.000000000000000000e+00 0.000000000000000000e+00 2 | 0.000000000000000000e+00 8.743057892980546697e+00 0.000000000000000000e+00 3 | 0.000000000000000000e+00 -0.000000000000000000e+00 8.743057892980546697e+00 4 | -------------------------------------------------------------------------------- /test/xcoord.dat: -------------------------------------------------------------------------------- 1 | 1.250000000000000000e-01 1.250000000000000000e-01 1.250000000000000000e-01 2 | 3.750000000000000000e-01 3.750000000000000000e-01 1.250000000000000000e-01 3 | 3.750000000000000000e-01 1.250000000000000000e-01 3.750000000000000000e-01 4 | 1.250000000000000000e-01 3.750000000000000000e-01 3.750000000000000000e-01 5 | 1.250000000000000000e-01 1.250000000000000000e-01 6.250000000000000000e-01 6 | 3.750000000000000000e-01 3.750000000000000000e-01 6.250000000000000000e-01 7 | 3.750000000000000000e-01 1.250000000000000000e-01 8.750000000000000000e-01 8 | 1.250000000000000000e-01 3.750000000000000000e-01 8.750000000000000000e-01 9 | 1.250000000000000000e-01 6.250000000000000000e-01 1.250000000000000000e-01 10 | 3.750000000000000000e-01 8.750000000000000000e-01 1.250000000000000000e-01 11 | 3.750000000000000000e-01 6.250000000000000000e-01 3.750000000000000000e-01 12 | 1.250000000000000000e-01 8.750000000000000000e-01 3.750000000000000000e-01 13 | 1.250000000000000000e-01 6.250000000000000000e-01 6.250000000000000000e-01 14 | 3.750000000000000000e-01 8.750000000000000000e-01 6.250000000000000000e-01 15 | 3.750000000000000000e-01 6.250000000000000000e-01 8.750000000000000000e-01 16 | 1.250000000000000000e-01 8.750000000000000000e-01 8.750000000000000000e-01 17 | 6.250000000000000000e-01 1.250000000000000000e-01 1.250000000000000000e-01 18 | 8.750000000000000000e-01 3.750000000000000000e-01 1.250000000000000000e-01 19 | 8.750000000000000000e-01 1.250000000000000000e-01 3.750000000000000000e-01 20 | 6.250000000000000000e-01 3.750000000000000000e-01 3.750000000000000000e-01 21 | 6.250000000000000000e-01 1.250000000000000000e-01 6.250000000000000000e-01 22 | 8.750000000000000000e-01 3.750000000000000000e-01 6.250000000000000000e-01 23 | 8.750000000000000000e-01 1.250000000000000000e-01 8.750000000000000000e-01 24 | 6.250000000000000000e-01 3.750000000000000000e-01 8.750000000000000000e-01 25 | 6.250000000000000000e-01 6.250000000000000000e-01 1.250000000000000000e-01 26 | 8.750000000000000000e-01 8.750000000000000000e-01 1.250000000000000000e-01 27 | 8.750000000000000000e-01 6.250000000000000000e-01 3.750000000000000000e-01 28 | 6.250000000000000000e-01 8.750000000000000000e-01 3.750000000000000000e-01 29 | 6.250000000000000000e-01 6.250000000000000000e-01 6.250000000000000000e-01 30 | 8.750000000000000000e-01 8.750000000000000000e-01 6.250000000000000000e-01 31 | 8.750000000000000000e-01 6.250000000000000000e-01 8.750000000000000000e-01 32 | 6.250000000000000000e-01 8.750000000000000000e-01 8.750000000000000000e-01 33 | 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 34 | 0.000000000000000000e+00 2.500000000000000000e-01 2.500000000000000000e-01 35 | 2.500000000000000000e-01 0.000000000000000000e+00 2.500000000000000000e-01 36 | 2.500000000000000000e-01 2.500000000000000000e-01 0.000000000000000000e+00 37 | 0.000000000000000000e+00 0.000000000000000000e+00 5.000000000000000000e-01 38 | 0.000000000000000000e+00 2.500000000000000000e-01 7.500000000000000000e-01 39 | 2.500000000000000000e-01 0.000000000000000000e+00 7.500000000000000000e-01 40 | 2.500000000000000000e-01 2.500000000000000000e-01 5.000000000000000000e-01 41 | 0.000000000000000000e+00 5.000000000000000000e-01 0.000000000000000000e+00 42 | 0.000000000000000000e+00 7.500000000000000000e-01 2.500000000000000000e-01 43 | 2.500000000000000000e-01 5.000000000000000000e-01 2.500000000000000000e-01 44 | 2.500000000000000000e-01 7.500000000000000000e-01 0.000000000000000000e+00 45 | 0.000000000000000000e+00 5.000000000000000000e-01 5.000000000000000000e-01 46 | 0.000000000000000000e+00 7.500000000000000000e-01 7.500000000000000000e-01 47 | 2.500000000000000000e-01 5.000000000000000000e-01 7.500000000000000000e-01 48 | 2.500000000000000000e-01 7.500000000000000000e-01 5.000000000000000000e-01 49 | 5.000000000000000000e-01 0.000000000000000000e+00 0.000000000000000000e+00 50 | 5.000000000000000000e-01 2.500000000000000000e-01 2.500000000000000000e-01 51 | 7.500000000000000000e-01 0.000000000000000000e+00 2.500000000000000000e-01 52 | 7.500000000000000000e-01 2.500000000000000000e-01 0.000000000000000000e+00 53 | 5.000000000000000000e-01 0.000000000000000000e+00 5.000000000000000000e-01 54 | 5.000000000000000000e-01 2.500000000000000000e-01 7.500000000000000000e-01 55 | 7.500000000000000000e-01 0.000000000000000000e+00 7.500000000000000000e-01 56 | 7.500000000000000000e-01 2.500000000000000000e-01 5.000000000000000000e-01 57 | 5.000000000000000000e-01 5.000000000000000000e-01 0.000000000000000000e+00 58 | 5.000000000000000000e-01 7.500000000000000000e-01 2.500000000000000000e-01 59 | 7.500000000000000000e-01 5.000000000000000000e-01 2.500000000000000000e-01 60 | 7.500000000000000000e-01 7.500000000000000000e-01 0.000000000000000000e+00 61 | 5.000000000000000000e-01 5.000000000000000000e-01 5.000000000000000000e-01 62 | 5.000000000000000000e-01 7.500000000000000000e-01 7.500000000000000000e-01 63 | 7.500000000000000000e-01 5.000000000000000000e-01 7.500000000000000000e-01 64 | 7.500000000000000000e-01 7.500000000000000000e-01 5.000000000000000000e-01 65 | -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | This directory contains small python scripts which may be used as subsidiary tools. 2 | 3 | Each Python scripts does the followings: 4 | 5 | * displace.py : script to generate input files of displaced configurations for VASP, Quantum-ESPRESSO, OpenMX, xTAPP, and LAMMPS. 6 | * extract.py : script to extract atomic displacements, forces, and total energies from output files. 7 | 8 | To use the scripts, Python environment (+ Numpy) is necessary. 9 | Usage of each script may be found in the header part of the source. 10 | 11 | 12 | -------------------------------------------------------------------------------- /tools/extract.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # extract.py 4 | # 5 | # Simple script to extract atomic displacements, atomic forces, and 6 | # energies from output files. 7 | # Currently, VASP, Quantum-ESPRESSO, and xTAPP are supported. 8 | # 9 | # Copyright (c) 2014, 2015, 2016 Terumasa Tadano 10 | # 11 | # This file is distributed under the terms of the MIT license. 12 | # Please see the file 'LICENCE.txt' in the root directory 13 | # or http://opensource.org/licenses/mit-license.php for information. 14 | # 15 | 16 | """ 17 | This python script extracts atomic displacements, atomics forces, 18 | and energies. 19 | """ 20 | 21 | from __future__ import print_function 22 | import numpy as np 23 | import optparse 24 | import interface.VASP as vasp 25 | import interface.QE as qe 26 | import interface.xTAPP as xtapp 27 | import interface.OpenMX as openmx 28 | import interface.LAMMPS as lammps 29 | 30 | usage = "usage: %prog [options] vasprun*.xml (or *.pw.out or *.str or *.md or *.out)" 31 | parser = optparse.OptionParser(usage=usage) 32 | 33 | parser.add_option('--VASP', 34 | metavar='orig.POSCAR', 35 | help="VASP POSCAR file with equilibrium atomic \ 36 | positions (default: None)") 37 | 38 | parser.add_option('--QE', 39 | metavar='orig.pw.in', 40 | help="Quantum-ESPRESSO input file with equilibrium\ 41 | atomic positions (default: None)") 42 | 43 | parser.add_option('--xTAPP', 44 | metavar='orig.cg', 45 | help="xTAPP CG file with equilibrium atomic \ 46 | positions (default: None)") 47 | 48 | parser.add_option('--LAMMPS', 49 | metavar='orig.lammps', 50 | help="LAMMPS structure file with equilibrium atomic positions (default: None)") 51 | 52 | parser.add_option('--OpenMX', 53 | metavar='orig.dat', 54 | help="OpenMX dat file with equilibrium atomic \ 55 | positions (default: None)") 56 | 57 | parser.add_option('--get', 58 | default="disp-force", 59 | help="specify which quantity to extract. \ 60 | Available options are 'disp-force', 'disp', 'force' and 'energy'.") 61 | 62 | parser.add_option('--unit', 63 | action="store", 64 | type="string", 65 | dest="unitname", 66 | default="Rydberg", 67 | help="print atomic displacements and forces in units of UNIT. \ 68 | Available options are 'eV', 'Rydberg' (default), and 'Hartree'.") 69 | 70 | parser.add_option('--offset', 71 | help="Specify an output file (either *.xml, *.pw.out, or *.str) of an\ 72 | equilibrium structure to subtract residual forces, displacements, or energies.") 73 | 74 | parser.add_option('--emin', 75 | default=None, 76 | type="float", 77 | help="Lower bound of the energy filter (eV) used for selecting output structures.\ 78 | Available only in the VASP parser.") 79 | 80 | parser.add_option('--emax', 81 | default=None, 82 | type="float", 83 | help="Upper bound of the energy filter (eV) used for selecting output structures.\ 84 | Available only in the VASP parser.") 85 | 86 | # Main 87 | 88 | if __name__ == "__main__": 89 | 90 | options, args = parser.parse_args() 91 | file_results = args[0:] 92 | 93 | if len(file_results) == 0: 94 | print("Usage: extract.py [options] vasprun*.xml \ 95 | (or *.pw.out, or *.str)") 96 | print() 97 | print("For details of available options, please type\n\ 98 | $ python displace.py -h") 99 | exit(1) 100 | 101 | # Check the calculator option 102 | 103 | conditions = [options.VASP is None, 104 | options.QE is None, 105 | options.xTAPP is None, 106 | options.LAMMPS is None, 107 | options.OpenMX is None] 108 | 109 | if conditions.count(True) == len(conditions): 110 | print("Error : Either --VASP, --QE, --xTAPP, --LAMMPS, --OpenMX option must be given.") 111 | exit(1) 112 | 113 | elif len(conditions) - conditions.count(True) > 1: 114 | print("Error : --VASP, --QE, --xTAPP, --LAMMPS, and --OpenMX cannot be given simultaneously.") 115 | exit(1) 116 | 117 | elif options.VASP: 118 | code = "VASP" 119 | file_original = options.VASP 120 | 121 | elif options.QE: 122 | code = "QE" 123 | file_original = options.QE 124 | 125 | elif options.xTAPP: 126 | code = "xTAPP" 127 | file_original = options.xTAPP 128 | 129 | elif options.LAMMPS: 130 | code = "LAMMPS" 131 | file_original = options.LAMMPS 132 | 133 | elif options.OpenMX: 134 | code = "OpenMX" 135 | file_original = options.OpenMX 136 | 137 | # Check output option 138 | str_get = options.get.lower() 139 | if str_get not in ["disp-force", "disp", "force", "energy"]: 140 | print("Error: Please specify which quantity to extract by the --get option.") 141 | exit(1) 142 | 143 | print_disp = False 144 | print_force = False 145 | print_energy = False 146 | 147 | if str_get == "disp-force": 148 | print_disp = True 149 | print_force = True 150 | elif str_get == "disp": 151 | print_disp = True 152 | elif str_get == "force": 153 | print_force = True 154 | elif str_get == "energy": 155 | print_energy = True 156 | 157 | # Check unit option 158 | str_unit = options.unitname.lower() 159 | if str_unit in ["ev", "electron_volt"]: 160 | str_unit = "ev" 161 | elif str_unit in ["ry", "ryd", "rydberg"]: 162 | str_unit = "rydberg" 163 | elif str_unit in ["ha", "hartree"]: 164 | str_unit = "hartree" 165 | else: 166 | print("Error: Invalid unit name : %s" % options.unitname) 167 | 168 | # Print data 169 | if code == "VASP": 170 | vasp.parse(file_original, file_results, 171 | options.offset, str_unit, 172 | print_disp, print_force, print_energy, 173 | options.emin, options.emax) 174 | 175 | elif code == "QE": 176 | qe.parse(file_original, file_results, 177 | options.offset, str_unit, 178 | print_disp, print_force, print_energy) 179 | 180 | elif code == "xTAPP": 181 | xtapp.parse(file_original, file_results, 182 | options.offset, str_unit, 183 | print_disp, print_force, print_energy) 184 | 185 | elif code == "OpenMX": 186 | openmx.parse(file_original, file_results, 187 | options.offset, str_unit, 188 | print_disp, print_force, print_energy) 189 | 190 | elif code == "LAMMPS": 191 | lammps.parse(file_original, file_results, 192 | options.offset, str_unit, 193 | print_disp, print_force, print_energy) 194 | -------------------------------------------------------------------------------- /tools/interface/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ttadano/ALM/f1d668fdee66e7e7218a04c88daf19d0e14fce0c/tools/interface/__init__.py --------------------------------------------------------------------------------