-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from robinzyb/devel
parse vibrational frequencies from vibrational analysis output
- Loading branch information
Showing
9 changed files
with
23,738 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import numpy as np | ||
|
||
HIRSHFELD_RE = re.compile( | ||
""" | ||
r""" | ||
\s+Hirshfeld\sCharges\s*\n | ||
\n | ||
\s\#.+\n | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import regex as re | ||
import numpy as np | ||
|
||
VIB_FREQ_RE = re.compile( | ||
r""" | ||
\sVIB\|Frequency\s\(cm\^-1\)(\s{0,15}(?P<vib_freq>[\s-]\d+\.\d+)){1,3} | ||
""", | ||
re.VERBOSE | ||
) | ||
|
||
|
||
def parse_vibration_freq_list(output_file): | ||
|
||
vib_freq_list = [] | ||
for match in VIB_FREQ_RE.finditer(output_file): | ||
#vib_freq_list.append(match["energy"]) | ||
for vib_freq in match.captures('vib_freq'): | ||
vib_freq_list.append(vib_freq) | ||
|
||
if vib_freq_list: | ||
return np.array(vib_freq_list, dtype=float) | ||
else: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
tests/test_vibrational_analysis/test_vibrational_analysis.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from cp2kdata.output import Cp2kOutput | ||
import os | ||
import json | ||
import pytest | ||
import numpy as np | ||
|
||
|
||
def json_to_dict(json_file): | ||
with open(json_file, "r") as fp: | ||
dict_content = json.load(fp) | ||
return dict_content | ||
|
||
|
||
vibrational_analysis_output_path_list = [ | ||
'tests/test_vibrational_analysis/v7.1/normal', | ||
|
||
] | ||
|
||
vibrational_analysis_output_list = [ | ||
Cp2kOutput(os.path.join(path, 'output')) for path in vibrational_analysis_output_path_list | ||
] | ||
|
||
|
||
test_params = list(zip(vibrational_analysis_output_list, | ||
vibrational_analysis_output_path_list)) | ||
|
||
|
||
@pytest.fixture(params=test_params, scope='class', ids=vibrational_analysis_output_path_list) | ||
def output_and_answer_path(request): | ||
return request.param | ||
|
||
# @pytest.fixture | ||
# def answer_in_dict(output_and_answer_path): | ||
# answer = json_to_dict( | ||
# os.path.join( | ||
# output_and_answer_path[1], | ||
# "answer", | ||
# "answer.json" | ||
# ) | ||
# ) | ||
# return answer | ||
|
||
class TestEnergyForce(): | ||
def test_run_type(self, output_and_answer_path): | ||
a_test_output = output_and_answer_path[0] | ||
run_type = a_test_output.get_run_type() | ||
assert run_type == 'VIBRATIONAL_ANALYSIS' | ||
|
||
def test_atomic_forces_list(self, output_and_answer_path): | ||
a_test_output = output_and_answer_path[0] | ||
vib_freq = a_test_output.get_vib_freq_list() | ||
if a_test_output.has_force(): | ||
answer = np.load( | ||
os.path.join( | ||
output_and_answer_path[1], | ||
"answer", | ||
"vib_freq.npy" | ||
) | ||
) | ||
assert np.all(vib_freq == answer) | ||
|
Binary file not shown.
Oops, something went wrong.