示例#1
0
    def readmps(self, filename):
        line1 = False
        line2 = False
        conversion = False
        d = None
        quad = None
        q = None
        r = None
        element = None
        with open(filename, "r") as f:

            for line in f.readlines():
                a = line.split()
                if "Units angstrom" in line:
                    conversion = 1
                elif "Units bohr" in line:
                    conversion = 0.52917721092
                elif "Rank" in line:
                    #print line
                    element = a[0]
                    rank = int(a[5])
                    if conversion != False:
                        r = conversion * np.array(a[1:4], dtype=float)
                    line1 = True
                elif len(a) == 1 and line1:
                    q = float(a[0])
                    line2 = True
                elif len(a) == 3 and line1 and line2:
                    d = np.array(a[0:3], dtype=float)
                    line3 = True
                elif len(
                        a
                ) == 5 and line1 and line2 and line3 and "P" not in line:
                    quad = np.array(a[0:], dtype=float)
                    line3 = True
                elif "P" in line and line1 and line2:
                    p = np.array(a[1:], dtype=float)
                    #print p
                    ptensor = np.array([[p[0], p[1], p[2]], [p[1], p[3], p[4]],
                                        [p[2], p[4], p[5]]])
                    line1 = False
                    line2 = False
                    line3 = False
                    at = atom(element, r)
                    if quad == None:
                        quad = np.zeros(5)
                    if d == None:
                        d = np.zeros(3)
                    at.setmultipoles(q, d, quad, ptensor)
                    self.updateatom(at)

        self.calccoG()

        return
 def readmps(self,filename):
     line1=False
     line2=False
     conversion=False
     d=None
     quad=None
     q=None
     r=None
     element=None
     with open(filename,"r") as f:
 
         for line in f.readlines():
             a=line.split()
             if "Units angstrom" in line:
                 conversion=1
             elif "Units bohr" in line:
                 conversion=0.52917721092
             elif "Rank" in line:
                 #print line
                 element=a[0]
                 rank=int(a[5])
                 if conversion!=False:
                     r=conversion*np.array(a[1:4],dtype=float) 
                 line1=True
             elif len(a)==1 and line1:
                 q=float(a[0])
                 line2=True
             elif len(a)==3 and line1 and line2:
                 d=np.array(a[0:3],dtype=float) 
                 line3=True
             elif len(a)==5 and line1 and line2 and line3 and "P" not in line:
                 quad=np.array(a[0:],dtype=float) 
                 line3=True
             elif "P" in line and line1 and line2:
                 p=np.array(a[1:],dtype=float)
                 #print p
                 ptensor=np.array([[p[0],p[1],p[2]],[p[1],p[3],p[4]],[p[2],p[4],p[5]]])
                 line1=False
                 line2=False
                 line3=False
                 at=atom(element,r)
                 if quad==None:
                     quad=np.zeros(5)
                 if d==None:
                     d=np.zeros(3)
                 at.setmultipoles(q,d,quad,ptensor)
                 self.updateatom(at)
     
     self.calccoG()
     
     return
 def readxyzfile(self,filename):
         noofatoms=None
         with open(filename,"r") as f:
             for line in f.readlines():
                 if line[0]=="#":
                     continue
                 entries=line.split()
                 if len(entries)==0:
                     continue
                 elif len(entries)==1:
                     noofatoms=int(entries[0])
                 elif len(entries)==4:
                     name=entries[0]
                     pos=np.array(entries[1:],dtype=float)
                     
                     self.atomlist.append(atom(name,pos))
         self.calccoG()
         return
示例#4
0
    def readxyzfile(self, filename):
        noofatoms = None
        with open(filename, "r") as f:
            for line in f.readlines():

                if line[0] == "#":
                    continue
                entries = line.split()
                if len(entries) == 0:
                    continue
                elif len(entries) == 1 and RepresentsInt(entries[0]):
                    noofatoms = int(entries[0])
                elif len(entries) != 4 or (not RepresentsFloat(entries[1])
                                           or not RepresentsFloat(entries[2])
                                           or not RepresentsFloat(entries[3])):
                    self.name = line
                elif len(entries) == 4:
                    name = entries[0]
                    pos = np.array(entries[1:], dtype=float)
                    self.atomlist.append(atom(name, pos))

        self.calccoG()
        return