def read(source_file, *args, **kwargs): """ Read an input file of various formats. Arguments: source_file: The first argument is a structure file of some format. The remaining args and kwargs are passed to the methods called to read the structure. If the structure name contains "cif" or "POSCAR" it will be read as one of these formats. Failing that, the file is passed to the ASE read method, and the returned Atoms object is then converted to a Structure. Examples:: >>> io.read(INSTALL_PATH+'/io/files/POSCAR_FCC') >>> io.read(INSTALL_PATH+'/io/files/fe3o4.cif') """ try: if 'cif' in source_file: return cif.read(source_file, *args, **kwargs) elif ( 'POSCAR' in source_file or 'CONTCAR' in source_file ): return poscar.read(source_file, *args, **kwargs) else: return ase.io.read(source_file, *args, **kwargs) except: try: return poscar.read(source_file, *args, **kwargs) except Exception: pass try: return cif.read(source_file, *args, **kwargs) except Exception: pass raise FormatNotSupportedError('The file %s is in an unrecognized format\ and cannot be read' % source_file)
def read(source_file, *args, **kwargs): """ Read an input file of various formats. Arguments: source_file: The first argument is a structure file of some format. The remaining args and kwargs are passed to the methods called to read the structure. If the structure name contains "cif" or "POSCAR" it will be read as one of these formats. Failing that, the file is passed to the ASE read method, and the returned Atoms object is then converted to a Structure. Examples:: >>> io.read(INSTALL_PATH+'/io/files/POSCAR_FCC') >>> io.read(INSTALL_PATH+'/io/files/fe3o4.cif') """ try: if 'cif' in source_file: return cif.read(source_file, *args, **kwargs) elif ('POSCAR' in source_file or 'CONTCAR' in source_file): return poscar.read(source_file, *args, **kwargs) else: return ase.io.read(source_file, *args, **kwargs) except: try: return poscar.read(source_file, *args, **kwargs) except Exception: pass try: return cif.read(source_file, *args, **kwargs) except Exception: pass raise FormatNotSupportedError('The file %s is in an unrecognized format\ and cannot be read' % source_file)
def check_POTCAR(): #======================================================================= if __name__ == '__main__': args= docopt(__doc__) pitch= float(args['-p']) leven= args['--even'] _spin_polarized= args['--spin-polarize'] _break_symmetry= args['--break-symmetry'] _metal= args['--metal'] poscar_fname= args['POSCAR'] print ' Pitch of k points = {0:5.1f}'.format(pitch) poscar= poscar.POSCAR() poscar.read(poscar_fname) potcar= potcar.read_POTCAR() species= potcar['species'] encut= max(potcar['encut']) valences= potcar['valence'] a1= poscar.h[:,0] a2= poscar.h[:,1] a3= poscar.h[:,2] al= poscar.afac natms= poscar.num_atoms print " species:",species print " encut:",encut print " valences:",valences print " natms:",natms ntot= 0 nele= 0 for i in range(len(natms)): ntot= ntot +natms[i] nele= nele +natms[i]*int(valences[i]) if _spin_polarized: nbands= int(nele/2 *1.8) else: nbands= int(nele/2 *1.4) if nbands < 50: nbands= nele l1= al *math.sqrt(a1[0]**2 +a1[1]**2 +a1[2]**2) l2= al *math.sqrt(a2[0]**2 +a2[1]**2 +a2[2]**2) l3= al *math.sqrt(a3[0]**2 +a3[1]**2 +a3[2]**2) print ' Length of each axes:' print ' l1 = {0:10.3f}'.format(l1) print ' l2 = {0:10.3f}'.format(l2) print ' l3 = {0:10.3f}'.format(l3) k1= determine_num_kpoint(l1,pitch,leven) k2= determine_num_kpoint(l2,pitch,leven) k3= determine_num_kpoint(l3,pitch,leven) print ' Number of k-points: {0:2d} {1:2d} {2:2d}'.format(k1,k2,k3) ndiv= [k1,k2,k3] write_KPOINTS(_KPOINTS_name,_KPOINTS_type,ndiv) write_INCAR(_INCAR_name,encut,nbands)