Skip to content

Commit

Permalink
Merge pull request mantidproject#20544 from dymkowsk/AbinsGaussianFix
Browse files Browse the repository at this point in the history
Abins gaussian fix
  • Loading branch information
SimonHeybrock authored Sep 22, 2017
2 parents abf70ef + 77c655f commit 5b5c5a7
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Framework/PythonInterface/plugins/algorithms/Abins.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def PyInit(self):
self.declareProperty(FileProperty("PhononFile", "",
action=FileAction.Load,
direction=Direction.Input,
extensions=["phonon", "out", "outmol", "log"]),
extensions=["phonon", "out", "outmol", "log", "LOG"]),
doc="File with the data from a phonon calculation.")

self.declareProperty(FileProperty("ExperimentalFile", "",
Expand Down Expand Up @@ -610,7 +610,7 @@ def _validate_dft_file_extension(self, filename_full_path=None, expected_file_ex

# check extension of a file
found_filename_ext = os.path.splitext(filename_full_path)[1]
if found_filename_ext != expected_file_extension:
if found_filename_ext.lower() != expected_file_extension:
return dict(Invalid=True,
Comment=msg_err + "Output from DFT program " + dft_program + " is expected." +
" The expected extension of file is ." + expected_file_extension +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
03c06bc4afe62ae6e224fcb2e2d525c8
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8558dff4ff22e0e087220639b6e7acbc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2032778ae20e60af1de825be6248aff3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
149d08e3ec152b17663792ef7f3bf59b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b102805ec68153e4279ff4546ee92a5b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ee3349c525b6601afc84643acc49fdc8
1 change: 1 addition & 0 deletions Testing/Data/UnitTest/C6H5Cl_LoadGAUSSIAN.log.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
689a5221e1843b715ddf4430dc692026
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
98450f7b27e05c8a50232f2ffb85ec03
1 change: 1 addition & 0 deletions Testing/Data/UnitTest/C6H5Cl_LoadGAUSSIAN_data.txt.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
26850832776754a46affe765b25ca483
38 changes: 26 additions & 12 deletions scripts/AbinsModules/GeneralLoadDFTTester.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,27 @@ def _check_reader_data(self, correct_data=None, data=None, filename=None, extens
self.assertEqual(correct_data["attributes"]["advanced_parameters"], data["attributes"]["advanced_parameters"])
self.assertEqual(correct_data["attributes"]["hash"], data["attributes"]["hash"])
self.assertEqual(correct_data["attributes"]["DFT_program"], data["attributes"]["DFT_program"])
self.assertEqual(AbinsModules.AbinsTestHelpers.find_file(filename + "." + extension),
data["attributes"]["filename"])

try:
self.assertEqual(AbinsModules.AbinsTestHelpers.find_file(filename + "." + extension),
data["attributes"]["filename"])
except AssertionError:
self.assertEqual(AbinsModules.AbinsTestHelpers.find_file(filename + "." + extension.upper()),
data["attributes"]["filename"])

# check datasets
self.assertEqual(True, np.allclose(correct_data["datasets"]["unit_cell"], data["datasets"]["unit_cell"]))

def _check_loader_data(self, correct_data=None, input_dft_filename=None, extension=None):
def _check_loader_data(self, correct_data=None, input_dft_filename=None, extension=None, loader=None):

try:
read_filename = AbinsModules.AbinsTestHelpers.find_file(input_dft_filename + "." + extension)
dft_loader = loader(input_dft_filename=read_filename)
except ValueError:
read_filename = AbinsModules.AbinsTestHelpers.find_file(input_dft_filename + "." + extension.upper())
dft_loader = loader(input_dft_filename=read_filename)

loader = AbinsModules.LoadDMOL3(
input_dft_filename=AbinsModules.AbinsTestHelpers.find_file(input_dft_filename + "." + extension))
loaded_data = loader.load_formatted_data().extract()
loaded_data = dft_loader.load_formatted_data().extract()

# k points
correct_items = correct_data["datasets"]["k_points_data"]
Expand All @@ -96,7 +106,7 @@ def _check_loader_data(self, correct_data=None, input_dft_filename=None, extensi
self.assertEqual(True, np.allclose(np.array(correct_atoms["atom_%s" % item]["coord"]),
atoms["atom_%s" % item]["coord"]))

def _check(self, name=None, loader=None):
def check(self, name=None, loader=None):

extension = self._loaders_extensions[str(loader)]

Expand All @@ -110,7 +120,7 @@ def _check(self, name=None, loader=None):
self._check_reader_data(correct_data=correct_data, data=data, filename=name, extension=extension)

# check loaded data
self._check_loader_data(correct_data=correct_data, input_dft_filename=name, extension=extension)
self._check_loader_data(correct_data=correct_data, input_dft_filename=name, extension=extension, loader=loader)

def _read_dft(self, loader=None, filename=None, extension=None):
"""
Expand All @@ -120,13 +130,17 @@ def _read_dft(self, loader=None, filename=None, extension=None):
:returns: phonon data
"""
# 1) Read data
filename = AbinsModules.AbinsTestHelpers.find_file(filename=filename + "." + extension)
dft_reader = loader(input_dft_filename=filename)
try:
read_filename = AbinsModules.AbinsTestHelpers.find_file(filename=filename + "." + extension)
ab_initio_reader = loader(input_dft_filename=read_filename)
except ValueError:
read_filename = AbinsModules.AbinsTestHelpers.find_file(filename=filename + "." + extension.upper())
ab_initio_reader = loader(input_dft_filename=read_filename)

data = self._get_reader_data(dft_reader=dft_reader)
data = self._get_reader_data(dft_reader=ab_initio_reader)

# test validData method
self.assertEqual(True, dft_reader._clerk._valid_hash())
self.assertEqual(True, ab_initio_reader._clerk._valid_hash())

return data

Expand Down
7 changes: 4 additions & 3 deletions scripts/AbinsModules/LoadGAUSSIAN.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class LoadGAUSSIAN(AbinsModules.GeneralDFTProgram):
"""
Class for loading GAUSSIAN DFT vibrational data.
Class for loading GAUSSIAN ab initio vibrational data.
"""
def __init__(self, input_dft_filename):
"""
Expand Down Expand Up @@ -160,11 +160,12 @@ def _read_atomic_disp_block(self, file_obj=None, disp=None):
:param file_obj: file object from which we read
:param disp: list with x coordinates which we update [num_freq, num_atoms, dim]
"""
sub_block_start = "Atom AN X Y Z X Y Z X Y Z"
sub_block_start = "X Y Z X Y Z X Y Z"
self._parser.find_first(file_obj=file_obj, msg=sub_block_start)

num_atom = 0
line_size = len(sub_block_start.split())
# Atom AN X Y Z X Y Z X Y Z
line_size = len(sub_block_start.split()) + 2
freq_per_line = sub_block_start.count("X")

l = file_obj.readline().split()
Expand Down
8 changes: 4 additions & 4 deletions scripts/test/AbinsLoadCASTEPTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ def tearDown(self):
_gamma_sum = "squaricn_sum_LoadCASTEP"

def test_gamma_sum_correction(self):
self._check(name=self._gamma_sum, loader=AbinsModules.LoadCASTEP)
self.check(name=self._gamma_sum, loader=AbinsModules.LoadCASTEP)

# ===================================================================================
# | Use case: Gamma point calculation and no sum correction for Gamma point |
# ===================================================================================
_gamma_no_sum = "squaricn_no_sum_LoadCASTEP"

def test_gamma_no_sum_correction(self):
self._check(name=self._gamma_no_sum, loader=AbinsModules.LoadCASTEP)
self.check(name=self._gamma_no_sum, loader=AbinsModules.LoadCASTEP)

# ===================================================================================
# | Use case: more than one k-point and sum correction |
# ===================================================================================
_many_k_sum = "Si2-phonon_LoadCASTEP"

def test_sum_correction_single_crystal(self):
self._check(name=self._many_k_sum, loader=AbinsModules.LoadCASTEP)
self.check(name=self._many_k_sum, loader=AbinsModules.LoadCASTEP)

# ===================================================================================
# | Use case: more than one k-point without sum correction |
Expand All @@ -52,7 +52,7 @@ def test_sum_correction_single_crystal(self):
_many_k_no_sum = "Si2-sc_LoadCASTEP"

def test_no_sum_correction_single_crystal(self):
self._check(name=self._many_k_no_sum, loader=AbinsModules.LoadCASTEP)
self.check(name=self._many_k_no_sum, loader=AbinsModules.LoadCASTEP)

if __name__ == '__main__':
unittest.main()
10 changes: 5 additions & 5 deletions scripts/test/AbinsLoadCRYSTALTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def tearDown(self):
_phonon_dispersion_v2 = "MgO-222-DISP_LoadCRYSTAL"

def test_gamma_crystal(self):
self._check(name=self._gamma_crystal, loader=AbinsModules.LoadCRYSTAL)
self._check(name=self._set_crystal, loader=AbinsModules.LoadCRYSTAL)
self.check(name=self._gamma_crystal, loader=AbinsModules.LoadCRYSTAL)
self.check(name=self._set_crystal, loader=AbinsModules.LoadCRYSTAL)

def test_molecule(self):
self._check(name=self._molecule, loader=AbinsModules.LoadCRYSTAL)
self.check(name=self._molecule, loader=AbinsModules.LoadCRYSTAL)

def test_phonon_dispersion_crystal(self):
self._check(name=self._phonon_dispersion_v1, loader=AbinsModules.LoadCRYSTAL)
self._check(name=self._phonon_dispersion_v2, loader=AbinsModules.LoadCRYSTAL)
self.check(name=self._phonon_dispersion_v1, loader=AbinsModules.LoadCRYSTAL)
self.check(name=self._phonon_dispersion_v2, loader=AbinsModules.LoadCRYSTAL)

if __name__ == '__main__':
unittest.main()
4 changes: 2 additions & 2 deletions scripts/test/AbinsLoadDMOL3Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def tearDown(self):
_gamma_no_h_dmol3 = "Na2SiF6_LoadDMOL3"

def test_gamma_dmol3(self):
self._check(name=self._gamma_dmol3, loader=AbinsModules.LoadDMOL3)
self._check(name=self._gamma_no_h_dmol3, loader=AbinsModules.LoadDMOL3)
self.check(name=self._gamma_dmol3, loader=AbinsModules.LoadDMOL3)
self.check(name=self._gamma_no_h_dmol3, loader=AbinsModules.LoadDMOL3)

if __name__ == '__main__':
unittest.main()
25 changes: 21 additions & 4 deletions scripts/test/AbinsLoadGAUSSIANTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,29 @@ def tearDown(self):

# *************************** USE CASES ********************************************
# ===================================================================================
# | Use cases: molecular calculation for GAUSSIAN |
# | Use cases: molecular calculation for GAUSSIAN03 Hartree Fock, Unix |
# ===================================================================================
_molecule_gaussian = "C6H5Cl-LoadGAUSSIAN"
_gaussian_system1 = "C6H5Cl_LoadGAUSSIAN"

def test_gaussian_1(self):
self.check(name=self._gaussian_system1, loader=AbinsModules.LoadGAUSSIAN)

# ===================================================================================
# | Use cases: molecular calculation for GAUSSIAN03 DFT, Win |
# ===================================================================================
_gaussian_system2 = "BENZENE4_g03_win_LoadGAUSSIAN"

def test_gaussian_2(self):
self.check(name=self._gaussian_system2, loader=AbinsModules.LoadGAUSSIAN)

# ===================================================================================
# | Use cases: molecular calculation for GAUSSIAN09 DFT, Win |
# ===================================================================================
_gaussian_system3 = "BENZENE4_g09_win_LoadGAUSSIAN"

def test_gaussian_3(self):
self.check(name=self._gaussian_system3, loader=AbinsModules.LoadGAUSSIAN)

def test_molecule_gaussian(self):
self._check(name=self._molecule_gaussian, loader=AbinsModules.LoadGAUSSIAN)

if __name__ == '__main__':
unittest.main()

0 comments on commit 5b5c5a7

Please sign in to comment.