def readline_and_strip_and_skip(f, line, z): line1 = line.strip() line_lt = line1.split(',') while line: if (not line1): line = f.readline() line1 = line.strip() line_lt = line1.split(',') elif line1 and line1[0] == '!': line = f.readline() line1 = line.strip() line_lt = line1.split(',') elif line1 and line1[0] != '!' and z != ele.atomicnumber_reg( line_lt[1]): line = f.readline() line1 = line.strip() line_lt = line1.split(',') elif line1 and line1[0] != '!' and z == ele.atomicnumber_reg( line_lt[1]) and line_lt[0] == 'ecp': line = f.readline() line1 = line.strip() line_lt = line1.split(',') else: return (line, line1) else: return (line, line1)
def read_molpro_library_basis(basis, f, am, z, basis_contr_lt): while True: line = f.readline() #error control if len(line) == 0: print 'There is no such element in this file! \n 1. Continue 2. Exit \n' Ctrl_local_exit = raw_input('') if Ctrl_local_exit == '2': sys.exit(1) elif Ctrl_local_exit == '1': f.close() f = file(Usr_in_basis_name, 'r') Gbl_Z = raw_input( 'Please input what is the atomic number of the element that you want: ' ) z = int(Gbl_Z) else: print 'Wrong input, error exit!' sys.exit(1) #end of error control line_lt = line.split(' ') line_lt = filter(None, line_lt) if line[0] != '!' and line[0] != '*' and len( line_lt) > 2 and z == ele.atomicnumber_reg(line_lt[0]): basis.molpro_library_basis_in(f, line, am, basis_contr_lt) f.close() return True
def molpro_library_basis_in(self,The_File,line,am,contr): linelt=line.split(' ') linelt=filter(None,linelt) while line and self.Z==ele.atomicnumber_reg(linelt[0]): if linelt[1] in am: i='spdfghiklmn'.index(linelt[1]) line=self.molpro_library_basis_in_AG(The_File,line,self.LT_EXP_COE_LT[i],linelt[1],contr) for j in range(0,len(self.LT_EXP_COE_LT[i])): self.LT_EXP_LT[i].append(self.LT_EXP_COE_LT[i][j][0]) self.LT_COE_LT[i].append(self.LT_EXP_COE_LT[i][j][1:]) tmp_lt=map(list,zip(*self.LT_COE_LT[i])) del self.LT_COE_LT[i][:] self.LT_COE_LT[i].extend(tmp_lt) linelt=line.split(' ') linelt=filter(None,linelt) else: line=The_File.readline() linelt=line.split(' ') linelt=filter(None,linelt) while line and self.Z!=ele.atomicnumber_reg(linelt[0]): line=The_File.readline() linelt=line.split(' ') linelt=filter(None,linelt)
def molpro_regular_basis_in(self,The_File,linein,line_lt,lbr_am): '''Read molpro_regular basis set file''' line=linein if line and ele.atomicnumber_reg(line_lt[1])==self.Z: if line_lt[0]=='s': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_S,self.LT_COE_S,self.LT_EXP_COE_S,'s') return line elif line_lt[0]=='p': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_P,self.LT_COE_P,self.LT_EXP_COE_P,'p') return line elif line_lt[0]=='d': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_D,self.LT_COE_D,self.LT_EXP_COE_D,'d') return line elif line_lt[0]=='f': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_F,self.LT_COE_F,self.LT_EXP_COE_F,'f') return line elif line_lt[0]=='g': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_G,self.LT_COE_G,self.LT_EXP_COE_G,'g') return line elif line_lt[0]=='h': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_H,self.LT_COE_H,self.LT_EXP_COE_H,'h') return line elif line_lt[0]=='i': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_I,self.LT_COE_I,self.LT_EXP_COE_I,'i') return line elif line_lt[0]=='k': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_K,self.LT_COE_K,self.LT_EXP_COE_K,'k') return line elif line_lt[0]=='l': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_L,self.LT_COE_L,self.LT_EXP_COE_L,'l') return line elif line_lt[0]=='m': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_M,self.LT_COE_M,self.LT_EXP_COE_M,'m') return line elif line_lt[0]=='n': line=self.molpro_regular_basis_in_AG(The_File,line,self.LT_EXP_N,self.LT_COE_N,self.LT_EXP_COE_N,'n') return line else: return line else: return line
#end of error control try: if basis: pass except NameError: basis = Classes.Basis_set(z) pre_am = '' while line and line_lt[1]: if not Nest.is_number(line_lt[2]): library_basis_sc_lt = line_lt library_basis_lt = library_basis_sc_lt[:3] library_basis_contr_lt = library_basis_sc_lt[3:] lbr_am = library_basis_lt[0] pre_am = lbr_am lbr_element = library_basis_lt[1] lbr_element_atomicnumber = ele.atomicnumber_reg( lbr_element) lbr_basis_name = library_basis_lt[2].lower() try: fd = file( Usr_in_basis_name_default_dir + lbr_basis_name + '.libmol', 'r') except IOError: lbr_basis_name = lbr_basis_name.replace('-', '_') try: fd = file( Usr_in_basis_name_default_dir + lbr_basis_name + '.libmol', 'r') except IOError: print Usr_in_basis_name_default_dir + lbr_basis_name + '.libmol' + ' does not exist! Select a solution: ' + ' \n 1. Continue (Manually specify the default library file ) 2. Exit \n' Ctrl_local_exit = raw_input('') if Ctrl_local_exit == '2':
def molpro_regular_basis_in_AG(self,f,tmpline,basislt_EXP,basislt_COE,basislt_EXP_COE,AM): '''Read molpro_regular basis set file for each angular momentum.''' killslash_lt=tmpline.split('\n') tmpline1=killslash_lt[0] print self.element_name print AM while tmpline1 and tmpline1[0]==AM: tmpline1_lt=tmpline1.split(',') if ele.atomicnumber_reg(tmpline1_lt[1])!=self.Z: tmpline=f.readline() if basislt_COE: num1=len(basislt_COE[0]) else: num1=0 break if tmpline1_lt[0]==AM: # read in exp for item in tmpline1_lt[2:]: basislt_EXP.append(float(item)) tmpline=f.readline() killslash_lt=tmpline.split('\n') tmpline1=killslash_lt[0] num2=len(basislt_EXP) #skip the comment lines while tmpline1 and tmpline1[0]=='!': tmpline=f.readline() killslash_lt=tmpline.split('\n') tmpline1=killslash_lt[0] while tmpline1 and tmpline1[0]=='c': # read in coeff s tmpline1_lt=tmpline1.split(',') coe_mark_lt=tmpline1_lt[1].split('.') coe_tmp=[] for item in tmpline1_lt[2:]: coe_tmp.append(float(item)) for count_i in range(1,int(coe_mark_lt[0])): coe_tmp.insert(0,0) for count_i in range(int(coe_mark_lt[1]),num2): coe_tmp.append(0) basislt_COE.append(coe_tmp) tmpline=f.readline() killslash_lt=tmpline.split('\n') tmpline1=killslash_lt[0] # skip the comment lines while tmpline1 and tmpline1[0]=='!': tmpline=f.readline() killslash_lt=tmpline.split('\n') tmpline1=killslash_lt[0] if basislt_COE: num1=len(basislt_COE[0]) else: num1=0 if num1!=num2: for count_i in range(0,num2-num1): for item in basislt_COE: item.append(0) coe_tmp=[] for count_j in range(0,num1+count_i): coe_tmp.append(0) coe_tmp.append(1) basislt_COE.append(coe_tmp) tmp_lt=map(list,zip(*basislt_COE)) del basislt_EXP_COE[:] for i,item in enumerate(tmp_lt): item=[item] for j,jtem in enumerate(tmp_lt): if i==j: basislt_EXP_COE.append(item+jtem) return tmpline