File tree 4 files changed +46
-4
lines changed
4 files changed +46
-4
lines changed Original file line number Diff line number Diff line change 11
11
12
12
def _add_quality_report (directory , pif , inline = True ):
13
13
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
14
24
tar = tarfile .open ("tmp.tar" , "w" )
15
25
tar .add (os .path .join (directory , "OUTCAR" ))
16
26
tar .add (os .path .join (directory , "INCAR" ))
@@ -201,8 +211,11 @@ def convert(files=[], **kwargs):
201
211
if len (files ) < 1 :
202
212
raise ValueError ("Files needs to be a non-empty list" )
203
213
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 )
206
219
else :
207
220
prefix = os .path .join ("." , os .path .commonprefix (files ))
208
221
print ("Trying to use prefix {} from {}" .format (prefix , os .getcwd ()))
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ def get_outcar(self):
59
59
)])
60
60
61
61
def get_incar (self ):
62
+ if self .incar is None : return None
62
63
raw_path = self .incar
63
64
if raw_path [0 :2 ] == "./" :
64
65
raw_path = raw_path [2 :]
@@ -67,6 +68,7 @@ def get_incar(self):
67
68
)])
68
69
69
70
def get_poscar (self ):
71
+ if self .poscar is None : return None
70
72
raw_path = self .poscar
71
73
if raw_path [0 :2 ] == "./" :
72
74
raw_path = raw_path [2 :]
Original file line number Diff line number Diff line change @@ -227,6 +227,11 @@ def test_filename_robustness(self):
227
227
parser = VaspParser ('perov_relax_U' )
228
228
self .assertEquals (parser .get_name (), 'VASP' )
229
229
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
+
230
235
delete_example ('perov_relax_U' )
231
236
232
237
def test_fail_with_multiple_files (self ):
Original file line number Diff line number Diff line change 1
1
import unittest
2
- from dfttopif import directory_to_pif
2
+ from dfttopif import directory_to_pif , convert
3
3
import tarfile
4
4
import os
5
5
import shutil
6
- from pypif import pif
7
6
import glob
8
7
8
+
9
9
def delete_example (name ):
10
10
'''Delete example files that were unpacked
11
11
using the `unpack_example(path)` function
@@ -58,6 +58,28 @@ def test_VASP(self):
58
58
# Delete files
59
59
delete_example (name )
60
60
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
+
61
83
def test_PWSCF (self ):
62
84
'''
63
85
Test ability to parse PWSCF directories
You can’t perform that action at this time.
0 commit comments