Index: database/import_vasp_calc
===================================================================
--- database/import_vasp_calc	(revision 49)
+++ database/import_vasp_calc	(revision 50)
@@ -13,6 +13,22 @@
 import multiprocessing
 import traceback
 
+xc_dict = {'1':'LDA(HL)', 
+           '2':'LDA(CA/PZ)', 
+           '3':'LDA(WI)', 
+           '4':'GGA(PB)', 
+           '5':'GGA(PW86)', 
+           '6':'LM', 
+           '7':'PW91', 
+           '8':'PBE',
+           '9':'RPBE',
+           '10':'VWN',
+           '11':'B3LYP(VWN3 correction)',
+           '12':'B3LYP(VWN5 correction)',
+           '13':'AM05',
+           '14':'PBEsol',
+           '17':'BEEF',
+           '100':'CO'}
 def error(msg, *args):
     return multiprocessing.get_logger().error(msg, *args)
 
@@ -39,7 +55,6 @@
     #log = open('scan.log','w')
     _all = os.walk(os.path.abspath(path))
     calculator=None
-    xc_dict = {'8': 'PBE', '91': 'PW91', 'CA': 'LDA'}
     read_all_dir = 0
     filenames = []
     if os.path.exists(db):
@@ -90,10 +105,19 @@
         t2 = time()
         print 'timing: ', t2-t1
         if use_poscar:
-            constraints = read(path+'/POSCAR').constraints
+            try:
+                constraints = read(path+'/POSCAR').constraints
+            except IOError:
+                try:
+               	    constraints = read(path+'/POSCAR.gz').constraints
+                except IOError:
+                    try:
+               	        constraints = read(path+'/POSCAR.bz2').constraints
+                    except IOError:
+                        constraints = None
             Atoms.set_constraint(constraints)
             print 'get constraint from poscar', filetoread
-        else:
+        if not constraints:
             Atoms0 = read(filetoread, index=0)
             pos0 = Atoms0.positions
             pos = Atoms.positions
@@ -138,18 +162,24 @@
                         pot = 'PAW'
                     else:
                         pot = line[1]
+                elif line.startswith(' exchange correlation table for  LEXCH ='):
+                    xc_flag = line.split()[-1].upper()
+                    if xc_flag not in xc_dict.keys():
+                        raise ValueError('Unknown xc-functional flag found in POTCAR,'
+                                         ' LEXCH=%s' % xc_flag)
+                    xc = xc_dict[xc_flag]
                 elif line.startswith(' Dimension of arrays'):
                 #if line.startswith(' Dimension of arrays'):
                     read_para = 1
                 elif read_para:
-                    if 'LEXCH' in line:
-                        xc_flag = line.split()[2].upper()
-                        if xc_flag not in xc_dict.keys():
-                            raise ValueError('Unknown xc-functional flag found in POTCAR,'
-                                             ' LEXCH=%s' % xc_flag)
-                        xc = xc_dict[xc_flag]
-                    elif 'NKPTS' in line:
-                    #if 'NKPTS' in line:
+                    #if 'LEXCH' in line:
+                    #    xc_flag = line.split()[2].upper()
+                    #    if xc_flag not in xc_dict.keys():
+                    #        raise ValueError('Unknown xc-functional flag found in POTCAR,'
+                    #                         ' LEXCH=%s' % xc_flag)
+                    #    xc = xc_dict[xc_flag]
+                    #elif 'NKPTS' in line:
+                    if 'NKPTS' in line:
                         nkpts = int(line.split()[3])
                     elif 'ENCUT' in line:
                         encut = float(line.split()[2])
@@ -194,13 +224,17 @@
             #del con[id]
             record = con.select(filename=filetoread)
         if update_method:
-            id = con.reserve(filename=filetoread)
-            con.write(Atoms,functional = xc,path=path,code='VASP',filename=filetoread, version=version, potential=pot, encut=encut, enaug=enaug, lsol=lsol, ldipol=ldipol, nkpts=nkpts, constraint=False)
-            del con[id]
-            record = con.select(filename=filetoread)
-            id = next(record)['id'] 
-            con.update(id,user=user)
-            con.update(id,calculator='vasp')
+            try:
+            	id = con.reserve(filename=filetoread)
+            	con.write(Atoms,functional = xc,path=path,code='VASP',filename=filetoread, version=version, potential=pot, encut=encut, enaug=enaug, lsol=lsol, ldipol=ldipol, nkpts=nkpts, constraint=False)
+            	del con[id]
+            	record = con.select(filename=filetoread)
+            	id = next(record)['id'] 
+            	con.update(id,user=user)
+            	con.update(id,calculator='vasp')
+            except UnboundLocalError:
+                print 'err:',filetoread
+                return
 
     except (IndexError, ValueError):
         _log = 'failed: '+filetoread
@@ -251,7 +285,7 @@
     if args.j is None:
         project = 'gaussian'
     else:
-        project = int(args.j)
+        project = args.j
 
     #import_vasp_calculations('/data/users/tjiang/rkerber', con)
     #import_vasp_calculations('.', con, include_dir=['<opt_dir>'], exclude_dir=['<to_exclude_dir1>', '<to_exclude_dir2>'])
