Git Product home page Git Product logo

phonopy's Introduction

Version Badge Downloads Badge PyPI codecov

Phonopy

Phonon code. Phonopy user documentation is found at http://phonopy.github.io/phonopy/

Installation

See https://phonopy.github.io/phonopy/install.html.

Dependency

  • python>=3.8
  • numpy>=1.17.0
  • PyYAML>=5.3
  • matplotlib>=2.2.2
  • h5py>=3.0
  • spglib>=2.3
  • scipy (optional)
  • seekpath (optional)

Mailing list for questions

Usual phonopy questions should be sent to phonopy mailing list (https://sourceforge.net/p/phonopy/mailman/).

Development

The development of phonopy is managed on the develop branch of github phonopy repository.

  • Github issues is the place to discuss about phonopy issues.
  • Github pull request is the place to request merging source code.

Formatting

Formatting rule is written in pyproject.toml.

pre-commit

Pre-commit (https://pre-commit.com/) is mainly used for applying the formatting rule automatically. Therefore, the use is strongly encouraged at or before git-commit. Pre-commit is set-up and used in the following way:

  • Installed by pip install pre-commit, conda install pre_commit or see https://pre-commit.com/#install.
  • pre-commit hook is installed by pre-commit install.
  • pre-commit hook is run by pre-commit run --all-files.

Unless running pre-commit, pre-commit.ci may push the fix at PR by github action. In this case, the fix should be merged by the contributor's repository.

VSCode setting

  • Not strictly, but VSCode's settings.json may be written like

    "python.linting.flake8Enabled": true,
    "python.linting.flake8Args": ["--max-line-length=88", "--ignore=E203,W503"],
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": false,
    "python.linting.mypyEnabled": true,
    "python.linting.pycodestyleEnabled": false,
    "python.linting.pydocstyleEnabled": true,
    "python.formatting.provider": "black",
    "python.formatting.blackArgs": ["--line-length=88"],
    "python.sortImports.args": ["--profile", "black"],
    "[python]": {
        "editor.codeActionsOnSave": {
        "source.organizeImports": true
      },
    }

Documentation

Phonopy user documentation is written using python sphinx. The source files are stored in doc directory. Please see how to write the documentation at doc/README.md.

Tests

Tests are written using pytest. To run tests, pytest has to be installed. The tests can be run by

% pytest

phonopy's People

Contributors

1041176461 avatar ab5424 avatar anttikarttunen avatar atztogo avatar bhourahine avatar chazeon avatar cloudiiink avatar dependabot[bot] avatar dev-zero avatar erikfransson avatar exphp avatar ezanardi avatar henriquemiranda avatar hongritianqi avatar jageo avatar jochym avatar kgmat avatar ladyteam avatar lebecki avatar liang-jianxin avatar matk86 avatar neukirchen-212 avatar pjcon avatar pre-commit-ci[bot] avatar quantifiedcode-bot avatar rehnd avatar shanghui avatar shibu778 avatar shyuep avatar zerothi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phonopy's Issues

Bug found in the get_smallest_vectors function

For the following example POSCAR

FCC
1.0
0.0 0.5 0.5
0.5 0.0 0.5
0.5 0.5 0.0
1 1
d
0.0 0.0 0.0
0.5 0.5 0.5

When I use it in the following script

import numpy as np
from phonopy.interface.vasp import read_vasp
from phonopy import Phonopy

cell = read_vasp("POSCAR", ["Pb", "Te"])
phonopy = Phonopy(cell, np.diag([2, 2, 2]))
smallest_vectors, multiplicity = phonopy._primitive.get_smallest_vectors()
print(multiplicity)

I get the following answer

[[1 4]
 [2 1]
 [2 1]
 [2 1]
 [2 1]
 [2 1]
 [2 1]
 [6 4]
 [4 1]
 [1 2]
 [1 2]
 [1 2]
 [1 2]
 [1 2]
 [1 2]
 [4 5]]

On the second column of the last row (i.e. multiplicity[15, 1]), the multiplicity is 5. But for a crystalline material, it is impossible to have exactly 5 neighbors of equivalent distance especially in a FCC structure.
And the found smallest vectors are listed below

 [ 1. -1. -1.]
 [ 1. -1.  1.]
 [-1.  1. -1.]
 [-1.  1.  1.]
 [-1. -1.  1.]

It is clear that it is missing vector [1 1 -1].
I am not sure if similar bugs happen in other Bravais lattices.

tolerance qe and vasp

I produced one output for VASP and one for qe using the same numbers for the coordinates and for the cell parameters. If I try to compute the displacements for the unit cell (-d --dim="1 1 1") with the same tolerance (default one), I get two different symmetries and so a different number of displacements.

How it is possible?

I'm attaching phonopy outputs and the two inputs.

VASP:

phonopy -d --dim='1 1 1' --vasp
        _
  _ __ | |__   ___  _ __   ___   _ __  _   _
 | '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
 | |_) | | | | (_) | | | | (_) || |_) | |_| |
 | .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
 |_|                            |_|    |___/
                                       2.1.0

Python version 3.6.8
Spglib version 1.12.1
Calculator interface: vasp
Crystal structure was read from "POSCAR".
Displacements creation mode
Settings:
  Supercell: [1 1 1]
Spacegroup: P2_1/c (14)
Use -v option to watch primitive cell, unit cell, and supercell structures.

"phonopy_disp.yaml" and supercells have been created.

NOTE:
  Displacements information is written into "phonopy_disp.yaml" from v1.15.0.
  "disp.yaml" is still supported to read, but will be deprecated.
                 _
   ___ _ __   __| |
  / _ \ '_ \ / _` |
 |  __/ | | | (_| |
  \___|_| |_|\__,_|


Quantum espresso:

$ phonopy -d --dim='1 1 1' --pwscf -c qe.in
        _
  _ __ | |__   ___  _ __   ___   _ __  _   _
 | '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
 | |_) | | | | (_) | | | | (_) || |_) | |_| |
 | .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
 |_|                            |_|    |___/
                                       2.1.0

Python version 3.6.8
Spglib version 1.12.1
Calculator interface: qe
Crystal structure was read from "qe.in".
Displacements creation mode
Settings:
  Supercell: [1 1 1]
Spacegroup: P-1 (2)
Use -v option to watch primitive cell, unit cell, and supercell structures.

"phonopy_disp.yaml" and supercells have been created.

NOTE:
  Displacements information is written into "phonopy_disp.yaml" from v1.15.0.
  "disp.yaml" is still supported to read, but will be deprecated.
                 _
   ___ _ __   __| |
  / _ \ '_ \ / _` |
 |  __/ | | | (_| |
  \___|_| |_|\__,_|

$ phonopy -d --dim='1 1 1' --pwscf  --tolerance=1.4e-5 -c qe.in 
        _
  _ __ | |__   ___  _ __   ___   _ __  _   _
 | '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
 | |_) | | | | (_) | | | | (_) || |_) | |_| |
 | .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
 |_|                            |_|    |___/
                                       2.1.0

Python version 3.6.8
Spglib version 1.12.1
Calculator interface: qe
Crystal structure was read from "qe.in".
Displacements creation mode
Settings:
  Supercell: [1 1 1]
Spacegroup: P2_1/c (14)
Use -v option to watch primitive cell, unit cell, and supercell structures.

"phonopy_disp.yaml" and supercells have been created.

NOTE:
  Displacements information is written into "phonopy_disp.yaml" from v1.15.0.
  "disp.yaml" is still supported to read, but will be deprecated.
                 _
   ___ _ __   __| |
  / _ \ '_ \ / _` |
 |  __/ | | | (_| |
  \___|_| |_|\__,_|

qe-vasp.zip

tests: DeprecationWarning: invalid escape sequence \L

Tests print:

copying build/lib.freebsd-11.2-STABLE-amd64-3.6/phonopy/_spglib.so -> phonopy
/usr/ports/science/py-phonopy/work-py36/phonopy-2.0.0/phonopy/phonon/band_structure.py:212: DeprecationWarning: invalid escape sequence \L
  labels[i] = "$" + l.replace("LAMBDA", "\Lambda") + "$"
/usr/ports/science/py-phonopy/work-py36/phonopy-2.0.0/phonopy/phonon/band_structure.py:214: DeprecationWarning: invalid escape sequence \m
  labels[i] = "$\mathrm{%s}$" % l
/usr/ports/science/py-phonopy/work-py36/phonopy-2.0.0/phonopy/phonon/band_structure.py:210: DeprecationWarning: invalid escape sequence \D
  labels[i] = "$" + l.replace("DELTA", "\Delta") + "$"
/usr/ports/science/py-phonopy/work-py36/phonopy-2.0.0/phonopy/phonon/band_structure.py:208: DeprecationWarning: invalid escape sequence \S
  labels[i] = "$" + l.replace("SIGMA", "\Sigma") + "$"
/usr/ports/science/py-phonopy/work-py36/phonopy-2.0.0/phonopy/phonon/band_structure.py:206: DeprecationWarning: invalid escape sequence \G
  labels[i] = "$" + l.replace("GAMMA", "\Gamma") + "$"
/usr/ports/science/py-phonopy/work-py36/phonopy-2.0.0/phonopy/phonon/group_velocity.py:88: DeprecationWarning: invalid escape sequence \ 
  """

python-3.6 on FreeBSD

Possible bug in set_tensor_symmetry_PJ

Hi!

In a project using phonopy we encountered some strange behaviour when using phonopy --fc-spg-symmetry command line option.

The problem might be in the function set_tensor_symmetry_PJ in the file phonopy/harmonic/force_constants.py

cart_rot = np.array([similarity_transformation(lattice, rot).T
                     for rot in rotations])
cart_rot_inv = np.array([np.linalg.inv(rot) for rot in cart_rot])

and the similarity transform does

def similarity_transformation(rot, mat):
    """ R x M x R^-1 """
return np.dot(rot, np.dot(mat, np.linalg.inv(rot)))

so what will be returned is (lattice=L, rot(scaled)=R_s, rot(cartesian)=R_c)

R_c=(L R_s L^-1)^T = L^-T R_s^T L^T

but I think the correct transformation is (assuming the usual convention of having cell vectors as rows)

R_c=L^T R_s L^-T

If that is the case then the function should be

cart_rot = np.array([similarity_transformation(lattice.T, rot)
                     for rot in rotations])

Notice also that R^T = R^-1 if R is orthonormal (which it should be if it is a rotation matrix?) so instead the second line can be written as

cart_rot_inv = np.array([rot.T for rot in cart_rot])

to save some numeric precission / time

Sorry for my ignorance.

Sincerely Fredrik Eriksson

A possible “bug” in dealing with unit cell

Hi!
When I was using phononpy program to process phonon spectrum, I found a possible "bug". There were only three quite small imaginary frequencies in calculations of VASP, which could be ignored as shown below:

142 f/i= 0.004774 THz 0.029999 2PiTHz 0.159259 cm-1 0.019746 meV
143 f/i= 0.018306 THz 0.115023 2PiTHz 0.610638 cm-1 0.075709 meV
144 f/i= 0.018306 THz 0.115023 2PiTHz 0.610638 cm-1 0.075709 meV

However, unfortunately, I found that a series of imaginary frequencies appeared in hgh symmetric point path of brillouin zone as displayed in figure.
1

Due to limitation of computing resource, I cannot adopt a big supercell to recaculate the phonon. The crystal constants of unit cell of my calculations are near 8 A, 8 A, 27 A, respectively. After that, I have done some test in some small systems where the similar cases happened but vanished in a supercell.

Therefore, I would like to know why this happened?

Exclude certain groups of atoms in frozen phonon calc

Dear Professor Togo,

Is it possible that we ask Phonopy to neglect phonon modes for certain groups of atoms in frozen phonon calculations? If so, can you please give me some hint on how to do that? I have this need when studying hybrid inorganic-organic materials, for example, methylammonium lead iodide perovskite (MAPbI3) for which the organic cation MA's phonon modes are not relevant to the specific material phenomenon under our concern.

I believe many people have a similar need as I do, which is particularly salient when the irrelevant organic groups contain a large number of C, H, O, N, and S atoms for which evaluating the phonon modes are expensive.

So far I can only think of a brutal-force way to cheat Phonopy:
(1) given a starting structure of MAPbI3 in POSCAR, remove all MA's to obtain an effective structure of PbI3 in POSCAR_eff;
(2) generate POSCAR_eff-{number} with displaced Pb or I atoms using Phonopy from POSCAR_eff;
(3) make supercells of POSCAR using the transformation matrices between POSCAR_eff and POSCAR_eff-{number}, add all MA from these supercells back into the corresponding POSCAR_eff-{number}, and obtain POSCAR-{number} files containing all MA and PbI3 atoms;
(4) calculate the forces of POSCAR-{number} using VASP;
(5) remove forces on C, H, N atoms of MA in all disp-{number}/vasprun.xml files to obtain disp_eff-{number}/vasprun.xml;
(6) obtain FORCE_SETS from disp_eff-{number}/vasprun.xml using Phonopy and do all the postprocessing as usual.

It would be nice that there is a simple option that we can specify to ask Phonopy to neglect some atoms so that in steps (2) and (5) Phonopy acts as if these atoms simply don't exist. I understand this feature may not be implemented soon, so I wonder if you could provide me with some suggestions on where to look for in Phonopy to understand how Phonopy parses forces from vasprun.xml.

Thank you and best regards,
Wei

OptionParser module is deprecated

According to https://docs.python.org/2/library/optparse.html the OptionParser module is deprecated (you will also see the deprecation warning if you run pylint/flake8 or a similar linter on phonopy_argparse.py).
What would you like to use instead? The built-in argparse or Click?
Given the many options I would strongly recommend the latter since it has a much more powerful interface, like verifying datatypes, checking file arguments, etc.

Change of default non-analytical term corretion

I am planning to change the default non-analytical term correction method from the current one (Wang et al) to the other one (Gonze et al). The later can be used with --nac-method='gonze' at the latest versions.

To release it as the default NAC, what kind of message should I show?

Compatibility with windows environment

I am extending the packaging of spglib/phonopy to further platforms (osx and windows) - using conda-forge project. There is a problem with compilation under windows. See here: Build for python 2.7 and here:All builds

For now windows build is limited to python 3.5 which works. Note download counter on the package conda-forge package - only few days - 66 already. A lot of people use conda-forge channel. Maybe it is a good way to expand visibility of your software while removing part of the burden of making all packages yourself?

`get_equivalent_smallest_vectors` is slow

When computing eigenvectors for twisted bilayer graphene, I find that phonopy spends an extremely long amount of time at startup in a function called get_equivalent_smallest_vectors. With --readfc --hdf5, this function ends up dominating the entire computation.

         17133219 function calls (17127871 primitive calls) in 97.987 seconds                       
                                                                                                    
   Ordered by: cumulative time                                                                      
                                                                                                    
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)                             
        1    0.000    0.000   97.987   97.987 phonopy:3(<module>)                                   
        1    0.001    0.001   97.323   97.323 phonopy:37(<module>)                                  
        1    0.000    0.000   86.540   86.540 api_phonopy.py:295(set_force_constants)               
        1    0.000    0.000   86.540   86.540 api_phonopy.py:1150(_set_dynamical_matrix)            
        1    0.000    0.000   86.540   86.540 dynamical_matrix.py:84(__init__)                      
        1    0.364    0.364   86.526   86.526 dynamical_matrix.py:396(get_smallest_vectors)         
    28224   67.834    0.002   86.079    0.003 dynamical_matrix.py:358(get_equivalent_smallest_vectors)
   762348    4.322    0.000    8.251    0.000 linalg.py:2022(norm)                                  
        1    0.000    0.000    5.774    5.774 api_phonopy.py:482(write_yaml_band_structure)         
        1    0.051    0.051    5.774    5.774 band_structure.py:126(write_yaml)                     
        3    5.427    1.809    5.615    1.872 band_structure.py:188(_get_q_segment_yaml)            
    28224    0.020    0.000    5.239    0.000 cells.py:354(get_reduced_bases)                       
    28224    0.340    0.000    5.219    0.000 cells.py:364(get_Delaunay_reduction)                  
    28224    0.531    0.000    3.828    0.000 cells.py:395(get_shortest_bases_from_extented_bases)  
  1684288    3.669    0.000    3.669    0.000 {numpy.core.multiarray.dot}                           
        1    0.000    0.000    3.652    3.652 api_phonopy.py:448(set_band_structure)                
        1    0.000    0.000    3.652    3.652 band_structure.py:58(__init__)                        

I've been trying out various optimization strategies for this function and am working on a PR, which I will post shortly.

Possible NAC bug

Dear Professor Togo,

I want to report that Phonopy may have a bug that leads to spurious discontinuities in the band dispersion at gamma point after NAC. Let me use the case mp-540957-20180417 from PhononDB to demonstrate this.

Using the files downloaded from PhononDB via the above link, and a BORN file created by Phonopy from a primitive cell DFPT VASP calculation that I did myself, I get the following phonon band dispersion diagrams:
without NAC:
no_nac
and with NAC:
nac
The one without NAC matches the figure on the linked phonondb@kyoto-u page. The one with NAC does not have any spurious discontinuity and looks all right.

The band.conf file I used reads:
CELL_FILENAME = POSCAR-unitcell
DIM = 1 1 1
PRIMITIVE_AXES = 0 1/2 1/2 1/2 0 1/2 1/2 1/2 0
FC_SYMMETRY = .TRUE.
ATOM_NAME = Cs Te I
BAND = 0.0 0.0 0.0 0.5 0.0 0.5 0.625 0.25 0.625, 0.375 0.375 0.75 0.0 0.0 0.0 0.5 0.5 0.5 0.5 0.25 0.75 0.5 0.0 0.5
BAND_LABELS = $\Gamma$ X UK $\Gamma$ L W X

In comparison, I did another set of finite displacement calculations of the same material myself starting from a structure downloaded from ICSD. My relaxed structure and yours have the same space group symmetry and the difference mainly rests on the order of the symmetrically equivalent atoms in the POSCAR-unitcell files, which are FCC conventional unit cells 4 times as large. There are also some slight differences in the lattice constant and fractional atomic coordinates because I relaxed the primitive structure with PBEsol instead of PBE. To demonstrate that these differences should not matter meaningfully, here's the phonon dispersion diagram from my calculations without NAC:
no_nac.
It is evident that it matches the one from PhononDB above.

However, using the same BORN file as before, here's the band diagram I obtain after NAC:
nac
You see there is a discontinuity of the bands at \gamma point, in clear difference from the one above.

I attach all the relevant files here from which you can reproduce what I report above.
mp-540957-20180417_NAC.tar.gz

Could you please take a look?

Thanks and best regards,
Wei

irreps analysis with the NAC option

Dear Dr. Togo

I'm using phonopy together with abinit to calculate phonon dispersions. However, there seem to be two problems.

  1. With the --nac option, the mesh and band calculations produce quite different phonon frequencies at the gamma point. Can I know why are they different?
  2. The gamma-point phonon frequencies in the irreps analysis output file is not changing with the the --nac option and always stay with the zero Born effective charge values. Then how to analyze the raman/infrared activity once the --nac option is included?
    Thanks a lot for your help!

Wishes
Shang

pwscf with python3

Hi Togo,

it seems that pwscf parser is not working for python3 version:

Traceback (most recent call last):
  File "/usr/local/bin/phonopy", line 315, in <module>
    yaml_mode=settings.get_yaml_mode())
  File "/usr/local/lib/python3.5/dist-packages/phonopy/interface/__init__.py", line 73, in read_crystal_structure
    unitcell, pp_filenames = read_pwscf(unitcell_filename)
  File "/usr/local/lib/python3.5/dist-packages/phonopy/interface/pwscf.py", line 62, in read_pwscf
    pwscf_in = PwscfIn(open(filename).readlines())
  File "/usr/local/lib/python3.5/dist-packages/phonopy/interface/pwscf.py", line 191, in __init__
    self._collect(lines)
  File "/usr/local/lib/python3.5/dist-packages/phonopy/interface/pwscf.py", line 224, in _collect
    for tag, self._values in elements.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'

You need to change dict.iteritems to dict.items.

Anyway thanks for such a nice package, I am using it for my PhD studies :).

Much faster version of set_tensor_symmetry procedure

Hi!

I have written much faster version of the set_tensor_symmetry_function from the harmonic/force_constants.py. It avoids explicit for loops and uses some numpy trics for performance. The difference is substantial. For a large system (96at) it is few seconds vs. few minutes (or more). I have tested it against the old function - the results are identical. For large systems the old function was simply unusable. Here is the code, I hope you can use it in the next version (sorry for not providing pull request or diff - I do not have proper setup for this at the moment):

def set_tensor_symmetry(force_constants,
                    lattice,
                    positions,
                    rotations,
                    translations,
                    symprec):
"""
Full force constants are symmetrized using crystal symmetry.
This method extracts symmetrically equivalent sets of atomic pairs and
take sum of their force constants and average the sum.

Since get_force_constants_disps may include crystal symmetry, this method
is usually meaningless.
"""

# Create mapping table between an atom and the symmetry operated atom
# map[ i, j ]
# i: atom index
# j: operation index

# Sizes for convenience
N=len(rotations)
K=len(positions)

# Transform all positions by all symmetry operations
rpos=np.dot(positions,np.transpose(rotations,(0,2,1))) + translations

# Build NxKxKx3 tensor from transformed positions by extending first 
# dimension of the rot_pos tensor (KxNx3) and transposing indexes
#0,1,2,3 => 2,1,0,3 (NxKxKx3)
# Calculate difference betwean every position and every image 
# Position matrix (Kx3) is broadcasted to first two dimensions of rp
diff=positions-np.transpose(np.tile(rpos,(K,1,1,1)),(2,1,0,3))

# Find all cases where some image coincides with some position
m=(abs(diff-diff.round()) < symprec).all(axis=-1)

# Build the map using numpy extended indexing from the [0,...,K-1] vector
# extended to KxK
mapa=np.tile(np.arange(K,dtype=np.int),(K,1))

# Select only positions where some image coincides with some position
mapa=np.array([mapa[mr] for mr in m])

# Construct all carthesian rotations and inverse rotations and cache
# them for efficiency
cart_rot=np.array([similarity_transformation(lattice, rot).T 
                    for rot in rotations])
cart_rot_inv=np.array([np.linalg.inv(rot) for rot in cart_rot])

# Map first two indexes of force constants according to the map
fcm=np.array([force_constants[mapa[n],:,:,:][:,mapa[n],:,:] 
                for n in range(N)])

# For every symmetrically equivalent force constant tensor
# Make explicit similarity transformation of force constants:
# R_n dot ( F_n dot R_n^-1 )
# and build the full array of all of them.
# Due to the way numpy orders indexes we need at the end move 
# spatial index (1) to its proper position as panultimate index.
s=np.transpose(np.array([np.dot(cart_rot[n],
                                np.dot(fcm[n],cart_rot_inv[n])) 
                            for n in range(N)]),(0,2,3,1,4))

# Check identity with the old procedure
# fc_bak=force_constants.copy()
# set_tensor_symmetry_old(fc_bak,lattice,
#                                positions, rotations, translations, symprec)

# Set force_constants to average over all symmetry equivalent variants
force_constants=np.average(s,axis=0)

# Do the actual correctness check
#assert(abs(force_constants-fc_bak) < 1e-6).all()

pdos error

Dear developers,

I have encountered some bug in plotting projected DOS. I used VASP to run phonon calculations. The calculations ended normally and all files are complete. My structure is a supercell containing 128 atoms and the following is my pdos.conf file:

ATOM_NAME = Na P O
DIM = 1 1 1
MP = 8 8 8
SIGMA = 0.1
PDOS =  128

I can get the correct output if checkout to version v1.14.2 but got different errors in v2.1.1 and v2.0.0.

Error message using Phonopy v2.1.1:

$ phonopy -p -s pdos.conf
        _
  _ __ | |__   ___  _ __   ___   _ __  _   _
 | '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
 | |_) | | | | (_) | | | | (_) || |_) | |_| |
 | .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
 |_|                            |_|    |___/
                                       2.1.1

Python version 3.5.2
Spglib version 1.12.1
Crystal structure was read from "phonopy.yaml".
Mesh sampling mode
Settings:
  Sampling mesh: [8 8 8]
  Supercell: [1 1 1]
  Primitive matrix:
    [0.  0.  0.5]
    [0. 1. 0.]
    [-1.  0.  0.]
Spacegroup: P-42_1c (114)
Use -v option to watch primitive cell, unit cell, and supercell structures.

Forces and displacements are read from "FORCE_SETS".
Computing force constants...
Max drift of force constants: -0.068330 (yy) -0.000005 (xx)
Number of q-points on sampling mesh: 512
Calculating phonons on sampling mesh...
Calculating projected DOS...
Index number '128' is specified,
but it is not allowed to be larger than the number of atoms.
Traceback (most recent call last):
  File "/global/homes/h/hat003/.local/cori/3.5-anaconda/bin/phonopy", line 4, in <module>
    __import__('pkg_resources').run_script('phonopy==2.1.1', 'phonopy')
  File "/global/common/cori/software/python/3.5-anaconda/lib/python3.5/site-packages/pkg_resources/__init__.py", line 748, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/global/common/cori/software/python/3.5-anaconda/lib/python3.5/site-packages/pkg_resources/__init__.py", line 1517, in run_script
    exec(code, namespace, namespace)
  File "/global/u2/h/hat003/.local/cori/3.5-anaconda/lib/python3.5/site-packages/phonopy-2.1.1-py3.5-linux-x86_64.egg/EGG-INFO/scripts/phonopy", line 1098, in <module>
    legend=([np.array(x) + 1 for x in pdos_indices]))
  File "/global/homes/h/hat003/.local/cori/3.5-anaconda/lib/python3.5/site-packages/phonopy-2.1.1-py3.5-linux-x86_64.egg/phonopy/api_phonopy.py", line 1750, in plot_projected_dos
    draw_grid=False)
  File "/global/homes/h/hat003/.local/cori/3.5-anaconda/lib/python3.5/site-packages/phonopy-2.1.1-py3.5-linux-x86_64.egg/phonopy/phonon/dos.py", line 487, in plot
    flip_xy=flip_xy)
  File "/global/homes/h/hat003/.local/cori/3.5-anaconda/lib/python3.5/site-packages/phonopy-2.1.1-py3.5-linux-x86_64.egg/phonopy/phonon/dos.py", line 134, in plot_partial_dos
    raise ValueError
ValueError

Error message using Phonopy v2.0.0:

$  phonopy -p -s pdos.conf
        _
  _ __ | |__   ___  _ __   ___   _ __  _   _
 | '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
 | |_) | | | | (_) | | | | (_) || |_) | |_| |
 | .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
 |_|                            |_|    |___/
                                       2.0.0

Python version 3.6.7
Spglib version 1.12.1
Crystal structure was read from "POSCAR".
Mesh sampling mode
Settings:
  Sampling mesh: [8 8 8]
  Supercell: [1 1 1]
Spacegroup: P-42_1c (114)
Use -v option to watch primitive cell, unit cell, and supercell structures.

Computing force constants...
Max drift of force constants: -0.068330 (zz) -0.000005 (xx)
Number of q-points on sampling mesh: 512
Calculating phonons on sampling mesh...
Traceback (most recent call last):
  File "/Users/hanmeiTang/miniconda3/bin/phonopy", line 7, in <module>
    exec(compile(f.read(), __file__, 'exec'))
  File "/Users/hanmeiTang/repos/phonopy/scripts/phonopy", line 916, in <module>
    phonon.write_yaml_mesh()
  File "/Users/hanmeiTang/repos/phonopy/phonopy/api_phonopy.py", line 1234, in write_yaml_mesh
    self._mesh.write_yaml()
  File "/Users/hanmeiTang/repos/phonopy/phonopy/phonon/mesh.py", line 361, in write_yaml
    w.write("\n".join(lines))
OSError: [Errno 22] Invalid argument

Normal output from v1.14.2

        _
  _ __ | |__   ___  _ __   ___   _ __  _   _
 | '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
 | |_) | | | | (_) | | | | (_) || |_) | |_| |
 | .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
 |_|                            |_|    |___/
                                      1.14.2

Python version 3.6.7
Spglib version 1.11.1
Mesh sampling mode
Settings:
  Sampling mesh: [8 8 8]
  Supercell: [1 1 1]
Spacegroup: P-42_1c (114)
Computing force constants...
Max drift of force constants: -0.068330 (zz) -0.000005 (xx)
Number of q-points on sampling mesh: 512
Calculating phonons on sampling mesh...
Calculating partial PDOS...
/Users/hanmeiTang/miniconda3/lib/python3.6/site-packages/matplotlib/text.py:1191: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if s != self._text:
                 _
   ___ _ __   __| |
  / _ \ '_ \ / _` |
 |  __/ | | | (_| |
  \___|_| |_|\__,_|

Wishlist: Binary alternative to band.yaml

YAML is a very good format for configuration, but not so good for serializing big data. Here's how long it takes me just to call yaml.load on a 111 MB band.yaml file.

def yaml_load_time(path):
    import time, yaml, resource

    start = time.time()
    with open(path) as f:
        yaml.load(f)
    end = time.time()

    gb = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024 / 1024

    print('time: {:.02f} seconds'.format(end - start))
    print('max memory usage: {:.02f} GiB'.format(gb))

# 111 MB file
yaml_load_time('medium-band-news-3.yaml')

time: 652.31 seconds (!!!)
max memory usage: 7.02 GiB (!!!!)

On my own fork, I've been using a terrible hack to optionally replace band.yaml with a number of numpy .NPY files. (Obviously, this isn't what we should do in phonopy!) A more principled solution might be to add a config option that causes Phonopy to write some band.hdf5 file that has datasets for frequency, eigenvectors, q-points, etc.

Some notes:

  • Scripts like bandplot should also support the new format
  • If this gets added, it should be a separate option from --hdf5, because I can imagine good reasons why somebody might want to use force_constants.hdf5 but also have a readible band.yaml file. (also, it would break many things that currently use --hdf5)
    • idea: --band-format=hdf5. (default being --band-format=yaml)

Crash in phonopy-qha (1.11.2)

Hi Togo,
sometimes a crash can occur with phonopy-qha due to a cv of 0.
This can be fixed (hopefully) with the attached patch file. The error must be catched and treated, but then I dont know if a gamma of Zero is bad or not. Have a look at the patch...

phonopy-1.11.2_iac_rwth.zip

Windows incompatibility

Unfortunately there is a problem with all windows builds. Similar to spglib. Would you take a look at these builds @atztogo ? Maybe the problem is not very fundamental? I have no knowledge about writing extensions so I really cannot do anything about it. For now I will block windows builds and limit packages to linux/osx.

Unfolding does not pass tests

The uninittests for unfolding fail on recent (1.10.7, 1.10.8) builds:

$ python test_unfolding.py 

 FF
 ======================================================================
 FAIL: test_Unfolding_NaCl (__main__.TestUnfolding)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "test_unfolding.py", line 39, in test_Unfolding_NaCl
     self._compare(weights, "unfolding.dat")
   File "test_unfolding.py", line 59, in _compare
     self.assertTrue((np.abs(weights_in_file - weights) < 1e-3).all())
 AssertionError: False is not true

 ======================================================================
 FAIL: test_Unfolding_SC (__main__.TestUnfolding)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "test_unfolding.py", line 54, in test_Unfolding_SC
     self._compare(weights, "unfolding_to_atoms.dat")
   File "test_unfolding.py", line 59, in _compare
     self.assertTrue((np.abs(weights_in_file - weights) < 1e-3).all())
 AssertionError: False is not true

 ----------------------------------------------------------------------
 Ran 2 tests in 30.289s

 FAILED (failures=2)

I have removed this test from the set to be able to build the package,
but we need to fix it before 1.10.9.

Bug in dynamic structure factor

As pointed out by Cameron Dashwood, there is a bug in dynamic structure factor implementation.

I fixed this bug at c7a2cf9. I appreciate if you could test this fix. This fix is included in the develop branch of phonopy code.

invalid yaml output from --symmetry

A colleague found that --symmetry output cannot be read as YAML, because it is missing a closing brace on translation:

space_group_operations:
- rotation: # 1
  - [ 1,  0 , 0]
  - [ 0,  1 , 0]
  - [ 0,  0 , 1]
  translation: [ 0.00000,  0.00000,  0.00000       # <-- invalid yaml

Also, it would seem that point_group_type and site_point_group should maybe be wrapped in quotes, so that they are always strings.

# current output
site_point_group: 3m   # this is a string
site_point_group: 1    # this is an integer

# quoted output
site_point_group: '3m' # this is a string
site_point_group: '1'  # this is a string

Tested on develop (15c9c62) and master (2052ae2).

phonopy -f vasprun.xml error

I am trying to install phonopy in a CentOS machine. I have installed all the libraries needed. The isntallation worked fine. Now every example is working except the Si example. While trying "./phonopy -f vasprun.xml", I'm getting this:

counter (file index): Python 2.5 or later is needed.
For creating FORCE_SETS file with Python 2.4, you can use phonopy 1.8.5.1 with python-lxml .

My python -V shows:

Python 2.6.6

Some questions about POSCAR of phonopy

The POSCAR of Si that I imported from https://materialsproject.org/ library has 8 atoms, but there are 2 atoms in the example. Can I use this POSCAR as POSCAR-unitcell for calculation? This two kinds of POSCARS are used to calculate and results indicate similar curves but different ordinate scales. WHY? How can I fix my thermodynamic results without changing POSCAR?
image

Another problem is that when I expanded the cell, I used POSCAR-00x or SPOSCAR as POSCAR for vasp calculation. After that, whether POSCAR-unitcell was used as POSCAR when running "phonopy -t -p mesh.conf" to get the thermodynamic properties.

Force constant unit conversion

Hi,
I have used Phonopy with the ESPRESSO backed, and i understand that the FORCE_CONSTANTS are in Ry/au^2 but i need the force constant to be in eV/A**2. and the conversion factor is 0.4858682984. But when i try to do the unit conversion i am not getting any difference.

Can you please have a look at my script and help me rectify the issue.

the command i use is

phonopy --pwscf -c CeO2.in -p --factor 0.4858682984 -s mesh.conf

my mesh.conf is

DIM=4 4 4
MP=12 12 12
GAMMA_CENTER=.TRUE.
FORCE_CONSTANTS=Write

Thank you for your help

regards
Linu
Graduate student
University of Saskatchewan

setup.py requires numpy to work

The import numpy at the beginning of setup.py prevents things like pip install phonopy from working on a machine that doesn't have numpy installed.

I'm not sure how to best fix this myself, but it looks like there's an example of how to get around this in scipy's setup.py

Mutable values in defaults

I have used quantified code automatic style check on my repositories. It has found some issues with the code. Some are minor or not important but some are potentially quite serious. I will try to correct
these issues or accept their automatic fix into my tree. I am starting with the following issue: you should never use mutable data as a default value of the argument of the function.
This is potentially dangerous - if the mutable default value is changed inside the function the default will change for every subsequent call to the function and if it is returned and used it will influence every place it is used in the code. It is often a source for obscure and difficult to trace errors. The important feature here is that the defaults are not generated when the function is called but when they are defined. I do not know if you want this corrections as pull requests, diffs or some other form. This particular fix is commit 0b952cb - you can cherry-pick it from my tree or I will generate pull request (tell me against which branch you want it).

disp.yaml wrong symbol and mass

Hi, Togo

I am using your software for defect vibrational spectrum calculations (pwscf and vasp).
For my calculations I am using your FORCE_CONSTANTS file and displ.yaml.
It is awesome :). On pwscf it works fine, however for vasp displ.yaml it mixes atomic
symbols and masses.

For diamond
POTCAR

PAW_PBE C 08Apr2002
4.00000000000000000 
...

POSCAR

diamond 
    3.5620940727273465
      1.00 0.00 0.00
      0.00 1.00 0.00
      0.00 0.00 1.00
8
Direct
    0.000000000    0.000000000    0.000000000
    0.500000000    0.500000000    0.000000000
    0.000000000    0.500000000    0.500000000
    0.500000000    0.000000000    0.500000000
    0.250000000    0.250000000    0.250000000
    0.750000000    0.750000000    0.250000000
    0.750000000    0.250000000    0.750000000
    0.250000000    0.750000000    0.750000000    �

It generates disp.yaml

natom:  216
displacements:
- atom:    1
  direction:
    [   1.0000000000000000,  0.0000000000000000,  0.0000000000000000 ]
  displacement:
    [   0.0100000000000000,  0.0000000000000000,  0.0000000000000000 ]
- atom:    1
  direction:
    [  -1.0000000000000000,  0.0000000000000000,  0.0000000000000000 ]
  displacement:
    [  -0.0100000000000000,  0.0000000000000000,  0.0000000000000000 ]
lattice:
- [    10.686282218182040,     0.000000000000000,     0.000000000000000 ] # a
- [     0.000000000000000,    10.686282218182040,     0.000000000000000 ] # b
- [     0.000000000000000,     0.000000000000000,    10.686282218182040 ] # c
points:
- symbol: H  # 1
  coordinates: [  0.000000000000000,  0.000000000000000,  0.000000000000000 ]
  mass: 1.007940
- symbol: H  # 2
  coordinates: [  0.333333333333333,  0.000000000000000,  0.000000000000000 ]
  mass: 1.007940                                 �
...

with symbols H and masses 1.007940. I can overcome this in my software,
but in future it would be nice if you could fix that. By the way is it possible to contribute
to your code, I would like to optimise fc_symmetry which is very usefull for me.
Again thanks for such nice and usefull package.

t_max in QHA calculations via Python API

Hi,

As a user via the Python API for a QHA calculation, I want to create a Phonopy object and then call the set_thermal_properties method with, for example, a t_max=1000 and t_step=10. When I then call the get_thermal_properties method, the last 4 temperatures are truncated and I am left with T=[0, 10, ..., 950, 960] where I would expect the list to go to 1000.

I assume I am using the code correctly (if not, please advise) and the truncation is done as a side effect of the calculation, but I think it would be more reasonable to extend the temperature range automatically within Phonopy in order to return the temperature range that I, the user, expect when I pass in t_max as a parameter.

--cutoff-radius raises IndexError

When using cutoff-radius option to cutoff the force constant matrix phonopy issues an indexerror, i.e. it tries to access a non-existing element.

I run this command:

phonopy --siesta --cutoff-radius 10. -ps band.conf

I tried to debug this, to no avail.

PS. I am using the latest commit, and if you want a small test example, let me know.

Test `test_IXS_G_to_L` ocassionally fails

I cannot reproduce every time (only ocassionally does the test not pass) but I am getting test_IXS_G_to_L to fail. Full error log is here.
Here is snippet of the error message.

running install tests
..........................................F........
======================================================================
FAIL: test_IXS_G_to_L (spectrum.test_dynamic_structure_factor.TestDynamicStructureFactor)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/phonopy-1.13.2.107/test/spectrum/test_dynamic_structure_factor.py", line 102, in test_IXS_G_to_L
    S[:, i].sum(axis=1), data_cmp[:, i].sum(axis=1), atol=1e-1)
  File "/nix/store/3aqb8gxmjy4bd98zh01as7nrcyszf3c2-python3.6-numpy-1.15.1/lib/python3.6/site-packages/numpy/testing/_private/utils.py", line 1452, in assert_allclose
    verbose=verbose, header=header, equal_nan=equal_nan)
  File "/nix/store/3aqb8gxmjy4bd98zh01as7nrcyszf3c2-python3.6-numpy-1.15.1/lib/python3.6/site-packages/numpy/testing/_private/utils.py", line 789, in assert_array_compare
    raise AssertionError(msg)
AssertionError:
Not equal to tolerance rtol=1e-07, atol=0.1
(mismatch 10.0%)
 x: array([2.990558e+01, 8.017501e+00, 3.839426e+00, 2.339812e+00,
       1.633024e+00, 1.245578e+00, 1.107560e-03, 1.267848e-04,
       4.048384e-04, 2.625977e-01])
 y: array([2.990558e+01, 8.017501e+00, 3.839426e+00, 2.339812e+00,
       1.633024e+00, 1.245578e+00, 6.772900e-05, 3.625850e-04,
       2.829889e-02, 5.767737e-03])
----------------------------------------------------------------------
Ran 51 tests in 22.281s

I am trying to include phonopy in the nix package manager18.09 release. Here is the pull request that I have open NixOS/nixpkgs#46161

phonopy command line commands does not have precedence

When using phonopy it would be very useful if one could use a generic *.conf file with all the relevant options in the file and then on the command line select the run mode.

I.e.

CREATE_DISPLACEMENTS = .TRUE.

CELL_FILENAME = file.name
PM = .TRUE.
DIM = 20 1 1 
BAND = 0 0 0  1/2 0 0
BAND_POINTS = 201

BAND_LABELS = $\Gamma$ X

Will always do "band structure mode".

phonopy -d band.conf

etc. will also use band structure mode.

Having precedence on the CMD would be great (and probably less confusing?) :)

The SYMMETRY=.FALSE. gives error messages.

        _
  _ __ | |__   ___  _ __   ___   _ __  _   _
 | '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
 | |_) | | | | (_) | | | | (_) || |_) | |_| |
 | .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
 |_|                            |_|    |___/
                                   1.12.0-r9

Python version 2.7.12
Spglib version 1.9.10
Creating displacements
Settings:
  Supercell: [2 2 1]
Spacegroup: P1 (1)

disp.yaml and supercells have been created.
Traceback (most recent call last):
  File "<HOME>/.local/bin/phonopy", line 559, in <module>
    filename="phonopy_disp.yaml")
  File "<HOME>/.local/bin/phonopy", line 121, in finalize_phonopy
    w.write(str(phpy_yaml))
  File "<HOME>/.local/lib/python2.7/site-packages/phonopy/interface/phonopy_yaml.py", line 258, in __str__
    return "\n".join(self.get_yaml_lines())
  File "<HOME>/.local/lib/python2.7/site-packages/phonopy/interface/phonopy_yaml.py", line 184, in get_yaml_lines
    self._symmetry.get_dataset()['international'])
TypeError: 'NoneType' object has no attribute '__getitem__'

Tracking issue for various optimizations

Overview

I've made a number of optimizations locally on phonopy and want to start contributing things back upstream. I am creating an issue here to help me keep track (since it is not possible for me to make Issues on my own fork).

Here's a laundry list of things I will be trying to contribute:

  • Fix O(n^3) behavior in get_smallest_vectors
    • status: PR merged: #46
  • Expose a compute_permutation function implemented in C.
    • status: PR merged: #47
  • Use compute_permutation in distribute_fc2
    • status: PR merged: #48
    • Will make another PR to clean up an unnecessary helper function.
  • Only compute permutations for generators
    • status: I have decided against this for now since there are more pressing concerns.

Descriptions

Fix O(n^3) behavior in get_smallest_vectors

In the current version of get_smallest_equivalent_vectors, we:

  • do the following for all N positions:
    • compute the cartesian position (in supercell.get_positions())
    • obtain the position scaled by reduced_bases
    • round it into -0.5 < x < 0.5
  • ...but then only use TWO of the positions!

This makes get_smallest_vectors scale with O(n^3) when it really should only scale with O(n^2).

Expose a compute_permutation function implemented in C.

The code in _distribute_fc2 for locating atoms that overlap can be factored out and optimized to perform O(n log n) work instead of the O(n^2) overlap checks it currently does. This same function can then also be used to implement get_positions_sent_by_rot_inv. Two birds with one stone!

I've done this on my own local branches and the speedup on large structures is phenomenal (bringing get_positions_sent_by_rot_inv from 55 seconds down to 0.13 seconds). However, this was a long time ago; I need to update it to incorporate your recent improvements (distribute_fc2_all).

Only compute permutations for generators

To state the obvious, there is a group homomorphism between space group operators and permutations.
Therefore, to compute permutations for all space group operations, we can simply compute the generators and then compose them to find the rest.

This might not be necessary; compute_permutation is already pretty fast on the structures that I'm testing it on; however, I still need to benchmark it on a big structure that has screw and glide operations, which is where I think this optimization will become useful/necessary.

Using @property for setters and getters

Hello!

I've noticed that many places in the code use a style like get_my_property(self) such as in Phonopy/qha/eos.py where there is

def get_volume(self):
    if self._parameters is None:
        return None
    else:
        return self._parameters[3]

Python was designed with this kind of application in mind and provide the property() method as a replacement for this syntax.

@property
def volume(self):
        return self._parameters[3]

That way you can access the volume by doing

e = EOSFit(...)
e.run(...)
e.volume
# instead of:
# e.get_volume()

By the way, both of these codes are 'broken' in the sense that if you don't use EOSFit.run() they will not return None, but will instead give you an attribute error.

I would be happy to make these changes throughout the codebase and submit a pull request, but I wanted to check that you welcome such changes into the API.

Error after installation

Hi,

I'm getting an error "Phonopy-C extension needs to build properly" after installation of the latest phonopy version. Can you help ?

Thanks,
Anh

get_positions_sent_by_rot_inv is occasionally given inputs that fail to be symmetric (beyond numerical error)

Provided is a test case that causes the current version of phonopy to fail.

phonopy-rot-inv-error.tar.gz

$ phonopy --tolerance 2e-2 band.conf --fc-format=hdf5 --band-format=hdf5 --writefc
        _
  _ __ | |__   ___  _ __   ___   _ __  _   _
 | '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
 | |_) | | | | (_) | | | | (_) || |_) | |_| |
 | .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
 |_|                            |_|    |___/
                                      1.12.8

Warning: Force constants are not prepared.
Python version 3.6.4
Spglib version 1.10.3
Band structure mode
Settings:
  Supercell: [1 1 8]
Spacegroup: Pm (6)
Computing force constants...
Encounter some problem in compute_permutation.
Traceback (most recent call last):
  File "/home/lampam/.local/bin/phonopy", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/home/lampam/asd/clone/phonopy/scripts/phonopy", line 661, in <module>
    computation_algorithm=settings.get_fc_computation_algorithm())
  File "/home/lampam/asd/clone/phonopy/phonopy/api_phonopy.py", line 377, in produce_force_constants
    computation_algorithm=computation_algorithm)
  File "/home/lampam/asd/clone/phonopy/phonopy/api_phonopy.py", line 1320, in _run_force_constants_from_forces
    computation_algorithm=computation_algorithm)
  File "/home/lampam/asd/clone/phonopy/phonopy/harmonic/force_constants.py", line 87, in get_fc2
    computation_algorithm=computation_algorithm)
  File "/home/lampam/asd/clone/phonopy/phonopy/harmonic/force_constants.py", line 716, in _get_force_constants_disps
    computation_algorithm=computation_algorithm)
  File "/home/lampam/asd/clone/phonopy/phonopy/harmonic/force_constants.py", line 268, in solve_force_constants
    symprec)
  File "/home/lampam/asd/clone/phonopy/phonopy/harmonic/force_constants.py", line 591, in _solve_force_constants_svd
    symprec)
  File "/home/lampam/asd/clone/phonopy/phonopy/harmonic/force_constants.py", line 282, in get_positions_sent_by_rot_inv
    symprec)
  File "/home/lampam/asd/clone/phonopy/phonopy/harmonic/force_constants.py", line 865, in _compute_permutation_for_rotation
    symprec)
  File "/home/lampam/asd/clone/phonopy/phonopy/harmonic/force_constants.py", line 901, in _compute_permutation_c
    permutation_error()
  File "/home/lampam/asd/clone/phonopy/phonopy/harmonic/force_constants.py", line 889, in permutation_error
    raise ValueError("Input forces are not enough to calculate force constants, "
ValueError: Input forces are not enough to calculate force constants, or something wrong (e.g. crystal structure does not match).

Investigation

When it fails, it mentions the compute_permutation function that I added. Furthermore, when I try running a version of phonopy prior to that change (21cb9e3), the crash does not occur, and there are no error messages.

Since it appeared that this might be due to a bug in my contributions, I continued to look further into it.

What makes it fail?

To help answer this question, I added debug output to the compute_permutation C function to make it print the best distance it found whenever it failed to find any distances less than symprec.

  • All of the distances it printed were approximately equal to 0.025 A, which is quite a bit bigger than symprec=0.02 A! (so this isn't just numerical error)
  • I printed out the structures for positions and rot_pos in get_positions_sent_by_rot_inv, and these are included in the archive. Indeed, some atoms really do move by a distance of 0.025A between the two files.

This suggests something is wrong with the input to the function or how it is used, but looking further into it, I found to my surprise that get_positions_sent_by_rot_inv receives exactly the same input in both the new and old versions.

Why didn't the old version fail?

As it turns out, the bug already existed. It's just that old versions of phonopy didn't notice that anything was wrong. The reason it wasn't detected is thanks to these lines in the old version:

j = np.nonzero(np.sqrt(np.sum(diff ** 2, axis=1)) < symprec)[0]
rot_map[j] = i

Deceptively, it looks like this should detect when there are no overlapping positions (by failing with an IndexError), but in fact it succeeds because np.nonzero actually returns a tuple.

So what used to happen when none of the positions were closer than symprec is that j would be an empty array, and rot_map[np.array([])] = i did nothing. In the end, there would be a bunch of extra 0s leftover in rot_map.

Files

Here's the link again: phonopy-rot-inv-error.tar.gz (12.4MB)

  • run: script to run phonopy with the right arguments
  • band.conf, FORCE_SETS, POSCAR: Input files
  • pos.vasp, rot.vasp: Structures showing positions and rot_pos received by get_positions_sent_by_rot_inv when it fails.

Request: Mode Grüneisen parameter BandStructure getters

Hi,

I would like to access to the band structure raw data in the Gruineisen BandStructure class:

https://github.com/atztogo/phonopy/blob/c5cd2ad57ae834c3afcf585e6374d95d21d39b7e/phonopy/gruneisen/band_structure.py#L38

which now are stored in self._path.
I think a simple collection of getters like in phonon BandStructure class would be enough:

https://github.com/atztogo/phonopy/blob/c5cd2ad57ae834c3afcf585e6374d95d21d39b7e/phonopy/phonon/band_structure.py#L57

thanks

Creating displacements with the quiet option does not write a phonopy_disp.yaml

Given any POSCAR (reproduced with the following):

Al1
1.0
2.473329 0.000000 1.427977
0.824443 2.331877 1.427977
0.000000 0.000000 2.855955
Al
1
direct
0.000000 0.000000 0.000000 Al

Running phonopy -q -d --dim='3 3 3' does not create a phonopy_disp.yaml (it still correctly creates the SPOSCAR and POSCAR-001 that I would expect). Running phonopy -d --dim='3 3 3' gives me the expected POSCARs and the expected phonopy_disp.yaml.

I am using phonopy==2.2.0 on Python 3.7

opening ''__nanoversion__.txt'' in setup.py

Its a very minor issue.
'pip install phonopy' fails because the version on pypi(1.10.4.59) tries to open the aforementioned file in setup.py. I noticed that the version on github doesnt have that problem. It would be nice to have a pip installable version so that packages that use phonopy can add it as a requirement in their setup.py files..

Some tests fail

Tests fail in the FreeBSD port:

======================================================================
ERROR: Failure: ImportError (cannot import name _spglib)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/local/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/local/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/ports/science/py-phonopy/work-py27/phonopy-1.13.2.107/test/structure/test_grid_points.py", line 4, in <module>
    from phonopy.structure.grid_points import GridPoints
  File "/usr/ports/science/py-phonopy/work-py27/phonopy-1.13.2.107/phonopy/__init__.py", line 36, in <module>
    from phonopy.api_phonopy import Phonopy
  File "/usr/ports/science/py-phonopy/work-py27/phonopy-1.13.2.107/phonopy/api_phonopy.py", line 40, in <module>
    from phonopy.structure.symmetry import Symmetry
  File "/usr/ports/science/py-phonopy/work-py27/phonopy-1.13.2.107/phonopy/structure/symmetry.py", line 37, in <module>
    import phonopy.structure.spglib as spg
  File "/usr/ports/science/py-phonopy/work-py27/phonopy-1.13.2.107/phonopy/structure/spglib.py", line 35, in <module>
    from phonopy import _spglib as spg
ImportError: cannot import name _spglib

Siesta reading discards LatticeVector units for non-Bohr unit

When using phonopy to create the displacement table for Siesta I find that it only corrects the positions depending on the LatticeConstant, and not the LatticeVectors.

I.e. when it writes out the supercell afterwards the fractional coordinates are correct while the supercell becomes too small.

Thanks for this great software!

Bug in dynmat2fc function

Hi Togo,

I found that recently a bug has been introduced in the dynmat2fc function. The dimension of the array containing the force constants obtained by this function are wrong.
Ex: in silicon with a supercell of 2x2x2 the dimensions of FC should be: (64, 64, 3, 3) but I obtain (2, 64, 3, 3) instead.
I checked different versions on phonopy available in PyPI and it seems that this bug is introduced between versions 1.12.6.26 and 1.12.6.32.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.