Exemple #1
0
    def load(self):
        "Rewrite load method"
        PosCar.load(self)
        with open(self.filename, 'r') as f:
            for i in range(self.totline):
                f.readline()
            #get dimension of 3d array
            grid = f.readline().strip(whitespace)
            empty = not grid  # empty row
            while empty:
                grid = f.readline().strip(whitespace)
                empty = not grid
            x, y, z = line2list(grid, dtype=int)
            #read electron localization function data
            elf_data = []
            for line in f:
                datalist = line2list(line)
                elf_data.extend(datalist)
        #########################################
        #                                       #
        #           !!! Notice !!!              #
        # NGX is the length of the **0th** axis #
        # NGY is the length of the **1st** axis #
        # NGZ is the length of the **2nd** axis #
        #                                       #
        #########################################
        #reshape to 3d array
        elf_data = np.array(elf_data).reshape((x, y, z), order='F')
        #set attrs
        self.grid = x, y, z
        self.elf_data = elf_data

        return
Exemple #2
0
    def load(self):
        "Rewrite load method"
        PosCar.load(self)
        with open(self.filename(), 'r') as f:
            for i in xrange(self.totline):
                f.readline()
            #get dimension of 3d array
            grid = f.readline().strip(whitespace)
            empty = not grid  # empty row
            while empty:
                grid = f.readline().strip(whitespace)
                empty = not grid
            x, y, z = line2list(grid, dtype=int)
            #read electron localization function data
            elf_data = []
            for line in f:
                datalist = line2list(line)
                elf_data.extend(datalist)
        #########################################
        #                                       #
        #           !!! Notice !!!              #
        # NGX is the length of the **0th** axis #
        # NGY is the length of the **1st** axis #
        # NGZ is the length of the **2nd** axis #
        #                                       #
        #########################################
        #reshape to 3d array
        elf_data = np.array(elf_data).reshape((x, y, z), order='F')
        #set attrs
        self.grid = x, y, z
        self.elf_data = elf_data

        return
Exemple #3
0
    def load(self):
        "Load all data in file into array."
        data = []
        with open(self.filename, 'r') as f:
            for line in f:
                line = line.strip()
                if not line[0].isdigit():  # comment line or not
                    if not line.startswith('-'):
                        continue
                    elif not line[1].isdigit():
                        continue
                linedata = line2list(line, field=self.field,
                                     dtype=self.dtype)
                data.append(linedata)
        self.data = np.array(data)

        return data
Exemple #4
0
    def load(self):
        #locate informations
        with open(self.filename(), 'r') as f:
            total_forces = []
            tforce_regex = \
                re.compile(r'FORCES: max atom, RMS\s+(\d+\.\d+)\s+\d+\.\d+\s*')
            max_regex = re.compile(r'Number: max atom\s+(\d+)\s*')
            for i, line in enumerate(f):
                #locate force infomation
                if 'TOTAL-FORCE' in line:  # force info begins
                    fbegin = i
                elif 'RMS' in line:  # total force
                    m = tforce_regex.search(line)
                    total_force = float(m.group(1))
                    total_forces.append(total_force)
                elif 'Number' in line:
                    #atom number with max force on it
                    m = max_regex.search(line)
                    max_force_atom = int(m.group(1))
        #get information details
        #----------------- force info -------------------#
        if 'fbegin' in dir():
            #total force
            total_forces = np.array(total_forces)
            #atom forces
            atom_forces = []
            with open(self.filename(), 'r') as f:
                for i, line in enumerate(f):
                    if i > fbegin+1:
                        if '-'*10 in line:
                            break
                        atom_force = line2list(line)
                        atom_forces.append(atom_force)
            atom_forces = np.array(atom_forces)

            #set attrs
            self.total_forces = total_forces
            self.atom_forces = atom_forces
            self.max_force_atom = max_force_atom
        else:
            print ("Warning: " +
                   "the first electronic iteration is running, " +
                   "no force information is loaded.")

        return
Exemple #5
0
    def load(self):
        "Load all data in file into array."
        data = []
        with open(self.filename, 'r') as f:
            for line in f:
                line = line.strip()
                if not line:  # blank line
                    continue
                if not line[0].isdigit():  # comment line or not
                    if not line.startswith('-'):
                        continue
                    elif not line[1].isdigit() and line[1] != '.':
                        continue
                linedata = line2list(line, field=self.field, dtype=self.dtype)
                data.append(linedata)
        self.data = np.array(data)

        return data
Exemple #6
0
    def load(self):
        #locate informations
        with open(self.filename(), 'r') as f:
            total_forces = []
            tforce_regex = \
                re.compile(r'FORCES: max atom, RMS\s+(\d+\.\d+)\s+\d+\.\d+\s*')
            max_regex = re.compile(r'Number: max atom\s+(\d+)\s*')
            for i, line in enumerate(f):
                #locate force infomation
                if 'TOTAL-FORCE' in line:  # force info begins
                    fbegin = i
                elif 'RMS' in line:  # total force
                    m = tforce_regex.search(line)
                    total_force = float(m.group(1))
                    total_forces.append(total_force)
                elif 'Number' in line:
                    #atom number with max force on it
                    m = max_regex.search(line)
                    max_force_atom = int(m.group(1))
        #get information details
        #----------------- force info -------------------#
        if 'fbegin' in dir():
            #total force
            total_forces = np.array(total_forces)
            #atom forces
            atom_forces = []
            with open(self.filename(), 'r') as f:
                for i, line in enumerate(f):
                    if i > fbegin + 1:
                        if '-' * 10 in line:
                            break
                        atom_force = line2list(line)
                        atom_forces.append(atom_force)
            atom_forces = np.array(atom_forces)

            #set attrs
            self.total_forces = total_forces
            self.atom_forces = atom_forces
            self.max_force_atom = max_force_atom
        else:
            print("Warning: " + "the first electronic iteration is running, " +
                  "no force information is loaded.")

        return