Skip to content

Commit 5acbf01

Browse files
authored
Merge pull request #73 from WardLT/only_outcar
Support "convert" for VASP calculations that only include an OUTCAR
2 parents 2015149 + f83e77f commit 5acbf01

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

dfttopif/drivers.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111

1212
def _add_quality_report(directory, pif, inline=True):
1313
import tarfile
14+
15+
# Use VaspParser to identify OUTCAR and POSCAR files
16+
parser = VaspParser(directory)
17+
18+
# If we do not have an INCAR, we cannot run the quality report
19+
if parser.incar is None:
20+
print("Unable to generate quality report; directory lacks an INCAR file")
21+
return
22+
23+
# Create the tar file
1424
tar = tarfile.open("tmp.tar", "w")
1525
tar.add(os.path.join(directory, "OUTCAR"))
1626
tar.add(os.path.join(directory, "INCAR"))
@@ -201,8 +211,11 @@ def convert(files=[], **kwargs):
201211
if len(files) < 1:
202212
raise ValueError("Files needs to be a non-empty list")
203213

204-
if (len(files) == 1):
205-
return directory_to_pif(files[0], **kwargs)
214+
if len(files) == 1:
215+
if os.path.isfile(files[0]):
216+
return directory_to_pif(os.path.dirname(files[0]), **kwargs)
217+
else:
218+
return directory_to_pif(files[0], **kwargs)
206219
else:
207220
prefix = os.path.join(".", os.path.commonprefix(files))
208221
print("Trying to use prefix {} from {}".format(prefix, os.getcwd()))

dfttopif/parsers/vasp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def get_outcar(self):
5959
)])
6060

6161
def get_incar(self):
62+
if self.incar is None: return None
6263
raw_path = self.incar
6364
if raw_path[0:2] == "./":
6465
raw_path = raw_path[2:]
@@ -67,6 +68,7 @@ def get_incar(self):
6768
)])
6869

6970
def get_poscar(self):
71+
if self.poscar is None: return None
7072
raw_path = self.poscar
7173
if raw_path[0:2] == "./":
7274
raw_path = raw_path[2:]

tests/parsers/test_vasp.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ def test_filename_robustness(self):
227227
parser = VaspParser('perov_relax_U')
228228
self.assertEquals(parser.get_name(), 'VASP')
229229

230+
# Test the cutoff energy
231+
res = parser.get_cutoff_energy()
232+
self.assertEquals(400, res.scalars[0].value)
233+
self.assertEquals('eV', res.units)
234+
230235
delete_example('perov_relax_U')
231236

232237
def test_fail_with_multiple_files(self):

tests/test_pif.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import unittest
2-
from dfttopif import directory_to_pif
2+
from dfttopif import directory_to_pif, convert
33
import tarfile
44
import os
55
import shutil
6-
from pypif import pif
76
import glob
87

8+
99
def delete_example(name):
1010
'''Delete example files that were unpacked
1111
using the `unpack_example(path)` function
@@ -58,6 +58,28 @@ def test_VASP(self):
5858
# Delete files
5959
delete_example(name)
6060

61+
# Test if we only have a single OUTCAR
62+
unpack_example(os.path.join('examples', 'vasp', 'AlNi_static_LDA.tar.gz'))
63+
64+
# Remove all files but OUTCAR
65+
for f in os.listdir('AlNi_static_LDA'):
66+
if f != 'OUTCAR':
67+
os.unlink(os.path.join('AlNi_static_LDA', f))
68+
69+
# Run the conversion, check that it returns some data
70+
result = convert([os.path.join('AlNi_static_LDA', 'OUTCAR')])
71+
72+
found = False
73+
for conv_value, prop in enumerate(result.properties):
74+
if prop.name == "Converged":
75+
found = True
76+
break
77+
78+
self.assertTrue(found)
79+
self.assertEqual(True, result.properties[conv_value].scalars[0].value)
80+
81+
delete_example('AlNi_static_LDA')
82+
6183
def test_PWSCF(self):
6284
'''
6385
Test ability to parse PWSCF directories

0 commit comments

Comments
 (0)