Skip to content

Commit d7eb480

Browse files
authored
Merge pull request #2 from pierre-24/modify_masses
Modify the masses
2 parents b21143d + 14b789a commit d7eb480

File tree

12 files changed

+544
-99
lines changed

12 files changed

+544
-99
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: ['3.10', '3.11']
18+
python-version: ['3.10', '3.11', '3.12']
1919

2020
steps:
2121
- uses: actions/checkout@v2

DOCUMENTATION.md

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# Documentation
2+
3+
## Install
4+
5+
To install this package, you need a running Python 3 installation (Python >= 3.10 recommended), and
6+
7+
```bash
8+
pip3 install git+https://github.com/pierre-24/phonopy-vibspec.git
9+
```
10+
11+
Note: as this script install programs, you might need to add their location (such as `$HOME/.local/bin`, if you use `--user`) to your `$PATH`, if any.
12+
13+
## Theory
14+
15+
For an intro to phonon calculations, see [the VASP documentation](https://www.vasp.at/wiki/index.php/Phonons:_Theory).
16+
17+
Long story short, in order to get a spectra, one needs to:
18+
19+
1. Compute the dynamic matrix (also called mass-weighted hessian) and diagonalize it, which will provide the frequencies and modes, and
20+
2. Compute the Born charge in order to compute the IR intensities and/or their derivatives to get the Raman intensities.
21+
22+
## Usage
23+
24+
### Frequencies and normal modes
25+
26+
To get the force constant, you need to use [`Phonopy`](https://phonopy.github.io/phonopy/index.html) (which is installed since it is a dependency of this package) as usual.
27+
28+
On the one hand, if you can use [DFPT](https://phonopy.github.io/phonopy/vasp-dfpt.html#vasp-dfpt-interface) (which is recommended), the procedure is the following:
29+
30+
```bash
31+
# 1. Create POSCAR of supercell:
32+
phonopy -d --dim="1 1 1" -c unitcell.vasp
33+
# Note: use preferentially a larger cell!
34+
35+
# 2. cleanup
36+
rm POSCAR-*
37+
mv SPOSCAR POSCAR
38+
39+
# 3. Run VASP using `IBRION` (see below)
40+
vasp_std
41+
42+
# 4. Extract force constants (a `force_constants.hdf5` file is created)
43+
phonopy --hdf5 --fc vasprun.xml
44+
```
45+
46+
For step 3, the [`IBRION`](https://www.vasp.at/wiki/index.php/IBRION) keyword should be set to 5, 6, 7, or 8 (more info [there](https://www.vasp.at/wiki/index.php/IBRION#Computing_the_phonon_modes)).
47+
When using numerical differentiation (`IBRION=5` or `IBRION=6`), convergence criterion should be stricter.
48+
For example:
49+
50+
```text
51+
IBRION = 6 ! numerical differentiation, using symmetry
52+
NFREE = 2 ! central differences for the force, should be 2 or 4
53+
POTIM = 0.015 ! displacement, default is 0.015
54+
EDIFF = 1.0e-08 ! stricter criterion for energy convergence
55+
PREC = Accurate ! increase precision
56+
```
57+
58+
You might also want to increase [`NELM`](https://www.vasp.at/wiki/index.php/NELM) since `EDIFF` is increased.
59+
60+
On the other hand, (see [there](https://phonopy.github.io/phonopy/vasp.html)):
61+
62+
```bash
63+
# 1. Create POSCAR of supercell:
64+
phonopy -d --dim="1 1 1" -c unitcell.vasp
65+
# Note: use preferentially a larger cell
66+
67+
# 2. Create folders for calculations
68+
for i in POSCAR-*; do a=${i/POSCAR/disp}; mkdir -p $a; mv $i ${a}/POSCAR; done;
69+
70+
# 3. Run VASP using `IBRION=-1` (see below)
71+
vasp_std
72+
73+
# 4. Extract force sets
74+
phonopy -f disp-*/vasprun.xml
75+
76+
# 5. Compute force constants (a `force_constants.hdf5` file is created)
77+
phonopy --writefc-format HDF5 --writefc
78+
```
79+
80+
Again, for step 3, you need to set:
81+
82+
```text
83+
EDIFF = 1.0e-08 ! stricter criterion for energy convergence
84+
PREC = Accurate ! increase precision
85+
```
86+
87+
### Visualisation and interpretation of the normal modes
88+
89+
If you want, you can then create files to visualize the modes in [VESTA](http://jp-minerals.org/vesta/en/):
90+
91+
```bash
92+
phonopy-vs-modes --modes="4 5 6"
93+
```
94+
95+
A `modexxx.vesta` is created per mode.
96+
97+
Furthermore, a partial analysis of normal modes is available: it estimates the percentage of translation, rotation, and vibration of normal modes.
98+
99+
```bash
100+
phonopy-vs-analyze-modes
101+
```
102+
103+
However, to determine the rotation, the program needs a center of rotation.
104+
By default, it is taken as the center of mass. You can manually set it with `-C`, *e.g.* `-C ".5 .5 .5"` for the center of the cell (this center is to be given in **fractional coordinates**).
105+
It is also possible to "unwrap" the cell (i.e., move atoms close together), which gives better results for single molecules.
106+
107+
**Note:** negative vibrational contributions are sometimes reported. Keep in mind that this is an estimate.
108+
109+
### Infrared spectrum
110+
111+
After obtaining the dynamic matrix, the frequencies and corresponding mode, you then need to run another calculation in order to compute the born effective charges and extract them using [a utility](https://phonopy.github.io/phonopy/auxiliary-tools.html#phonopy-vasp-born) provided by Phonopy:
112+
113+
```bash
114+
# 1. Run a calculation with `LEPSILON = .TRUE.` **on the unit cell**
115+
vasp_std
116+
117+
# 2. Extract Born effective charges from calculations (a `BORN` file is created)
118+
phonopy-vasp-born vasprun.xml > BORN
119+
```
120+
121+
For step 1, the `INCAR` file should use the following parameters (again, to ensure precision):
122+
123+
```text
124+
LEPSILON = .TRUE. ! Compute dielectric matrix
125+
PREC = Accurate
126+
EDIFF = 1.0e-08
127+
```
128+
129+
Then, you can create an IR spectrum:
130+
131+
```bash
132+
# 3. Get IR spectrum
133+
phonopy-vs-ir -b BORN spectrum.csv
134+
```
135+
136+
The `-b` option controls the location of the `BORN` file
137+
138+
The output CSV file contains two sections:
139+
140+
1. a list of each normal mode, its irreducible representation, and their IR activity, and
141+
2. a spectrum.
142+
143+
You can control the latter using different command line options:
144+
145+
+ `--limit 200:2000`, which create a graph between 200 and 2000 cm⁻¹;
146+
+ `--each=1`, the interval between each point (in cm⁻¹);
147+
+ `--linewidth=5`, the linewidth of the Lorentzian (in cm⁻¹);
148+
149+
It is also possible to compute spectra at other `q` points in the Brillouin zone:
150+
151+
```bash
152+
phonopy-vs-ir -q="0.5 0 0" spectrum_0.5.csv
153+
```
154+
155+
Note that Phonopy is generally not able to assign symmetry labels in that case.
156+
157+
## Raman spectrum
158+
159+
The procedure is more complex, since one needs the derivatives of the BORN charge with respect to polarizability (*i.e.*, the polarizability):
160+
161+
```bash
162+
# 1. Get displaced geometries
163+
phonopy-vs-prepare-raman
164+
165+
# 2. Create folders for calculations
166+
for i in dielec-*.vasp; do a=$(i%.vasp); mkdir -p $a; cd $a; ln -s ../$i POSCAR; cd ..; done;
167+
168+
# 3. Run calculations with `LEPSILON = .TRUE.` for each displaced geometry
169+
for i in dielec-*; do cd $i; vasp_std; cd ..; done
170+
171+
# 4. Collect dielectric constants
172+
phonopy-vs-gather-raman dielec-*/vasprun.xml
173+
174+
# 4. Get Raman spectrum
175+
phonopy-vs-raman spectrum.csv
176+
```
177+
178+
The resulting output contains the same sections as with IR (except it gives raman activities), and can be controlled using the same command line options.
179+
180+
## Contribute
181+
182+
Contributions, either with [issues](https://github.com/pierre-24/phonopy-vibspec/issues) or [pull requests](https://github.com/pierre-24/phonopy-vibspec/pulls) are welcomed.
183+
184+
### Install
185+
186+
If you want to contribute, this is the usual deal:
187+
start by [forking](https://guides.github.com/activities/forking/), then clone your fork and use the following install procedures instead.
188+
189+
```bash
190+
cd phonopy-vibspec
191+
192+
# definitely recommended in this case: use a virtualenv!
193+
python -m venv virtualenv
194+
source venv/bin/activate
195+
196+
# install also dev dependencies
197+
make install
198+
```
199+
200+
### Tips to contribute
201+
202+
+ A good place to start is the [list of issues](https://github.com/pierre-24/phonopy-vibspec/issues).
203+
In fact, it is easier if you start by filling an issue, and if you want to work on it, says so there, so that everyone knows that the issue is handled.
204+
205+
+ Don't forget to work on a separate branch.
206+
Since this project follows the [git flow](http://nvie.com/posts/a-successful-git-branching-model/), you should base your branch on `main`, not work in it directly:
207+
208+
```bash
209+
git checkout -b new_branch origin/main
210+
```
211+
212+
+ Don't forget to regularly run the linting and tests:
213+
214+
```bash
215+
make lint
216+
make test
217+
```
218+
219+
Indeed, the code follows the [PEP-8 style recommendations](http://legacy.python.org/dev/peps/pep-0008/), checked by [`flake8`](https://flake8.pycqa.org/en/latest/).
220+
Having an extensive test suite is also a good idea to prevent regressions.
221+
222+
+ Pull requests should be unitary, and include unit test(s) and documentation if needed.
223+
The test suite and lint must succeed for the merge request to be accepted.
224+
225+
## Who?
226+
227+
My name is [Pierre Beaujean](https://pierrebeaujean.net), and I have a Ph.D. in quantum chemistry from the [University of Namur](https://unamur.be) (Belgium).
228+
I'm the main (and only) developer of this project, used in our lab.
229+
I use this in the frame of my post-doctoral research in order to study batteries and solid electrolyte interphrase, and I developed this project to ease my life.
230+
231+
Note: due to my (quantum) chemistry background, we may speak of similar things using a different vocabulary.

README.md

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,73 +9,6 @@ Then, calculation(s) of the dielectric matrix provide the IR and Raman intensiti
99
Note: this is actually a simpler (and packaged!) version of [`Phonopy-Spectroscopy`](https://github.com/skelton-group/Phonopy-Spectroscopy). The main difference with the latter is that this package does not include phonon line widths (and thus does not require `phono3py`).
1010
If you are interested in that (or polarized Raman), use their code instead :)
1111

12-
## Install
12+
## Installation, usage, & contributions
1313

14-
To install this package, you need a running Python 3 installation (Python >= 3.10 recommended), and
15-
16-
```bash
17-
pip3 install git+https://github.com/pierre-24/phonopy-vibspec.git
18-
```
19-
20-
Note: as this script install programs, you might need to add their location (such as `$HOME/.local/bin`, if you use `--user`) to your `$PATH`, if any.
21-
22-
## Usage
23-
24-
Common procedure:
25-
```bash
26-
# 1. Create POSCAR of supercell:
27-
# (from https://phonopy.github.io/phonopy/vasp-dfpt.html#vasp-dfpt-interface)
28-
phonopy -d --dim="1 1 1" -c unitcell.vasp
29-
# Note: use preferentially a larger cell
30-
31-
# 2. cleanup
32-
rm POSCAR-*
33-
mv SPOSCAR POSCAR
34-
35-
# 3. Run VASP using `IBRION=8` or `IBRION=6` with appropriate `POTIM`
36-
37-
# 4. Extract force constants (a `force_constants.hdf5` file is created)
38-
phonopy --hdf5 --fc vasprun.xml
39-
```
40-
41-
Create files to vizualize the modes in [VESTA](http://jp-minerals.org/vesta/en/):
42-
43-
```bash
44-
phonpy-vs-modes --modes="4 5 6"
45-
```
46-
47-
For infrared:
48-
```bash
49-
# 1. Run a calculation with `LEPSILON = .TRUE.` **on the unit cell**
50-
51-
# 2. Extract Born effective charges from calculations
52-
phonopy-vasp-born vasprun.xml > BORN
53-
54-
# 3. Get IR spectrum
55-
phonopy-vs-ir spectrum.csv
56-
```
57-
58-
For Raman:
59-
```bash
60-
# 1. Get displaced geometries
61-
phonopy-vs-prepare-raman
62-
63-
# 2. Create folders for calculations
64-
for i in dielec-*.vasp; do a=$(i%.vasp); mkdir -p $a; cd $a; ln -s ../$i POSCAR; cd ..; done;
65-
66-
# 3. Run calculations with `LEPSILON = .TRUE.` for each displaced geometry
67-
68-
# 4. Collect dielectric constants
69-
phonopy-vs-gather-raman dielec-*/vasprun.xml
70-
71-
# 4. Get Raman spectrum
72-
phonopy-vs-raman spectrum.csv
73-
```
74-
75-
## Who?
76-
77-
My name is [Pierre Beaujean](https://pierrebeaujean.net), and I have a Ph.D. in quantum chemistry from the [University of Namur](https://unamur.be) (Belgium).
78-
I'm the main (and only) developer of this project, used in our lab.
79-
I use this in the frame of my post-doctoral research in order to study batteries and solid electrolyte interphrase, and I developed this project to ease my life.
80-
81-
Note: due to my (quantum) chemistry background, we may speak of similar things using a different vocabulary.
14+
See [DOCUMENTATION.md](DOCUMENTATION.md).

phonopy_vibspec/__init__.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,59 @@
1111
__email__ = 'pierre.beaujean@unamur.be'
1212
__status__ = 'Development'
1313

14+
from typing import Optional, Set
1415

1516
# logging
1617
logging.basicConfig(level=logging.WARNING)
1718
logger = logging.getLogger(__name__)
1819
logger.setLevel(os.environ.get('LOGLEVEL', 'WARNING').upper())
20+
21+
22+
class GetListWithinBounds:
23+
"""
24+
Get a list of integer within an interval `[min, max]`.
25+
Open intervals are possible by setting `None`.
26+
"""
27+
def __init__(self, min_index: Optional[int] = None, max_index: Optional[int] = None):
28+
self.min_index = min_index
29+
self.max_index = max_index
30+
31+
def _check_or_raise(self, n: int):
32+
"""Check that number fall in interval"""
33+
if self.min_index is not None and n < self.min_index:
34+
raise ValueError('{} should be larger than {}'.format(n, self.min_index))
35+
if self.max_index is not None and n > self.max_index:
36+
raise ValueError('{} should be smaller than {}'.format(n, self.max_index))
37+
38+
def __call__(self, inp: str) -> Set[int]:
39+
"""
40+
Get a list of atom indices.
41+
Ranges (i.e., `1-3` = `[0, 1, 2]`) and final wildcard (i.e., 2-*` = `[2, 3 ...]`, only if closed interval)
42+
are supported.
43+
"""
44+
lst = set()
45+
46+
for x in inp.split():
47+
if '-' in x:
48+
chunks = x.split('-')
49+
if len(chunks) != 2:
50+
raise ValueError('{} should contain 2 elements'.format(x))
51+
52+
b = int(chunks[0])
53+
self._check_or_raise(b)
54+
55+
if chunks[1] == '*':
56+
if self.max_index is None:
57+
raise ValueError('cannot use `*` with an open interval')
58+
e = self.max_index
59+
else:
60+
e = int(chunks[1])
61+
self._check_or_raise(e)
62+
63+
lst |= set(range(b, e + 1))
64+
else:
65+
n = int(x)
66+
self._check_or_raise(n)
67+
lst.add(int(x))
68+
69+
return lst

0 commit comments

Comments
 (0)