示例#1
0
 def is_properties_calculated(self, lines, properties_name):
     LR = ListReader(lines)
     if properties_name is "therm":
         return bool(LR.go_by_keys(self.stop_keys["thermochemistry"]["start"]))
     elif properties_name is "energy":
         return bool(LR.go_by_keys("E(PMP2)=", "E2(B2PLYPD)", "SCF Done:", "Energy="))
     elif properties_name is "force":
         return bool(LR.go_by_keys(self.stop_keys["force"]))
示例#2
0
 def get_EigV_optimization(self, lines) -> np.ndarray:
     part = []
     result = []
     LR = ListReader(lines)
     line = LR.go_by_keys(*self.stop_keys["EigV_opt"])
     result.extend(map(float, line.replace("\n", "").split()[2:]))
     part.append(line)
     part = LR.get_all_if_keys(*self.stop_keys["EigV_opt"])
     for line in part:
         result.extend(map(float, line.replace("\n", "").split()[2:]))
     return np.array(result)
示例#3
0
 def get_criteria(self, lines) -> dict:
     result = dict()
     LR = ListReader(lines)
     LR.go_by_keys(*self.stop_keys["crit_start"])
     part = LR.get_all_by_keys(*self.stop_keys["crit_end"])
     try:
         for line in part:
             result.update({line.split()[0] + " " + line.split()[1]: line.split()[2]})
         return result
     except:
         return np.nan
示例#4
0
def get_section_with_grad_iter(path_to_file):
    with open(path_to_file) as input_file:
        LR = ListReader(input_file)
        LR.go_by_keys(
            "Since a DF basis is specified, we compute 2- and 3-index integrals:"
        )
        while True:
            result = LR.get_all_by_end_and_keys(
                "Since a DF basis is specified, we compute 2- and 3-index integrals:"
            )
            if result:
                yield result
            else:
                break
示例#5
0
 def get_energy(self, lines):
     LR = ListReader(lines)
     if self.casscf:
         pass
     elif self.nroots is not 1 and not self.casscf:
         pass
     elif self.emperic:
         line = self._go_by_keys(lines, "Energy=")
         return float(line.split()[1].replace("D", "E"))
     elif self.nroots is 1 and not self.pt2:
         line = LR.go_by_keys("SCF Done:")
         return float(line.split()[4])
     elif self.nroots is 1 and self.pt2:
         line = LR.go_by_keys("E(PMP2)=", "E2(B2PLYPD)")
         return float(line.split()[-1].replace("D", "E"))
示例#6
0
 def get_coord(self, lines) -> tuple:
     LR = ListReader(lines)
     LR.go_by_keys(*self.stop_keys["opt_geom_start"])
     LR.go_by_keys("--------------------------")
     LR.get_next_lines(3)
     part = LR.get_all_by_keys(*self.stop_keys["opt_geom_end"])
     charges = []
     coords = []
     for line in part:
         charges.append(line.split()[1])
         coords.extend(map(float, line.replace("\n", "").split()[3:]))
     return charges, np.array(coords)
示例#7
0
def get_hessian(iterable):
    LR = ListReader(iterable)
    LR.go_by_keys("++ Symmetrized Mass Weighted Hessian ++")
    LR.get_next_lines(2)
    part = LR.get_all_by_keys(
        "* Projecting out translational and rotational degrees of freedom",
        "Mass Weighted Hessian Eigenvalues")
    temporary = []
    for line in part:
        try:
            [int(i) for i in line.replace("\n", "").split()[3]]
        except IndexError:
            pass
        except ValueError:
            if not "* Vibrational frequencies, " in line:
                if "averaged" in line:
                    print(1)
                temporary.append(
                    [float(i) for i in line.replace("\n", "").split()[1:]])
    ndim = int(math.sqrt((len(temporary) - 1) * 6 + len(temporary[-1])))
    hessian = np.zeros((ndim, ndim))
    for i in range(len(temporary)):
        for j in range(len(temporary[i])):
            index1 = (i // ndim) * 6
            index2 = (i % ndim)
            hessian[index1 + j, index2] = temporary[i][j]
    return np.array(hessian)
示例#8
0
def get_mrci_spectr(iterable):
    LR = ListReader(iterable)
    LR.go_by_keys("CI-EXCITATION SPECTRA")
    LR.go_by_keys(" ABSORPTION SPECTRUM")
    LR.get_next_lines(4)
    part = LR.get_all_by_end_and_keys("--------")
    energy_1 = float(part[0].split()[6])
    energy_2 = float(part[1].split()[6])
    foc_1 = float(part[0].split()[7])
    foc_2 = float(part[1].split()[7])
    if foc_1 > foc_2:
        return energy_1
    else:
        return energy_2
示例#9
0
 def get_force(self, lines) -> np.ndarray:
     LR = ListReader(lines)
     LR.go_by_keys(*self.stop_keys["force_start"])
     LR.get_next_lines(2)
     part = LR.get_all_by_keys(*self.stop_keys["force_end"])
     result = []
     for line in part:
         result.extend(map(float, line.replace("\n" , "").split()[2:]))
     return np.array(result)
示例#10
0
 def _get_opt_iterations(self):
     stop_key = self.parser.get_stop_key("opt_cycl")
     with open(self.file_name, "r") as open_file:
         LR = ListReader(open_file)
         if "pre_key" in stop_key.keys():
             LR.go_by_keys(*stop_key["pre_key"])
         part = []
         part.extend(LR.get_all_by_end_and_keys(*stop_key["start"]))
         part.extend(LR.get_all_by_end_and_keys(*stop_key["end"]))
         while part is not []:
             energy = self.parser.get_energy(part)
             charges, coords = self.parser.get_coord(part)
             forces = self.parser.get_force(part)
             criteries = self.parser.get_criteria(part)
             eing = self.parser.get_criteria(part)
             yield energy, charges, coords, forces, criteries, eing
             part = []
             part.extend(LR.get_all_by_end_and_keys(*stop_key["start"]))
             part.extend(LR.get_all_by_end_and_keys(*stop_key["end"]))
示例#11
0
 def get_berny_section(self, iterable):
     LR = ListReader(iterable)
     LR.go_by_keys(*self.stop_keys["opt_cycl"]["start"])
     LR.go_by_keys(*self.stop_keys["opt_cycl"]["start"])
     part = []
     part = LR.get_all_by_end_and_keys(*self.stop_keys["opt_cycl"]["start"])
     part.extend(LR.get_all_by_end_and_keys(*self.stop_keys["opt_cycl"]["start"]))
     while not part is []:
         yield part
         part = LR.get_all_by_end_and_keys(*self.stop_keys["opt_cycl"]["start"])
         temp = LR.get_all_by_end_and_keys(*self.stop_keys["opt_cycl"]["start"])
         try:
             part.extend(temp)
         except:
             break
     return
示例#12
0
 def get_MO(self, lines):
     LR = ListReader(lines)
     line = LR.go_by_keys(*self.stop_keys["pop_end"])
     coeff = []
     coeff.extend(map(float, line.replace("\n", "").split()[4:]))
     part = LR.get_all_if_keys(*self.stop_keys["pop_end"])
     for line in part:
         coeff.extend(map(float, line.replace("\n", "").split()[4:]))
     n_basis = len(coeff)
     MO = np.zeros((n_basis, n_basis))
     LR.get_next_lines(3)
     for i in range(int(n_basis/5)):
         part = LR.get_all_by_keys("Eigenvalues --")
         part = iter(part)
         j = 0
         for line in part:
             if j == n_basis:
                 break
             if len(line.split()) == 5:
                 break
             elif len(line.split()) == 9:
                 MO[i * 5: i * 5 + 5, j] = line.replace("\n", "").split()[4:]
             else:
                 MO[i * 5: i * 5 + 5, j] = line.replace("\n", "").split()[2:]
             j = j + 1
     last_orb = n_basis % 5
     part = LR.get_all_by_keys("orbital", "pop", "Density Matrix:")
     j = 0
     i = int(n_basis/5)
     res = n_basis % 5
     if res is not 0:
         for line in part:
             if len(line.split()) == last_orb + 4:
                 MO[i * 5: i * 5 + res, j] = line.replace("\n", "").split()[4:]
             else:
                 MO[i * 5: i * 5 + res, j] = line.replace("\n", "").split()[2:]
             j = j + 1
     for i in range(MO.shape[0]):
         for j in range(MO.shape[1]):
             MO[i, j] = float(MO[i, j])
     return coeff, MO
示例#13
0
 def get_hessian(self, lines):
     LR = ListReader(lines)
     LR.go_by_keys("The second derivative matrix:")
     LR.get_next_lines(1)
     part = LR.get_all_by_keys("ITU=  0")
     part1 = iter(part)
     n = 0
     for i in part1:
         try:
             _ = float(i.split()[1])
         except:
             break
         n = n + 1
     part = iter(part)
     hessian = np.zeros((n, n))
     i = 0
     shifts = int(n / 5)
     if n % 5 != 0:
         shifts = shifts + 1
     for j in range(shifts):
         for i in range(n - j*5):
             try:
                 line = next(part)
                 line = line.replace("\n", "")
                 l = i + 1
                 if l > 5:
                     l = 5
                 hessian[i + j*5, j*5: j*5 + l] = [x for x in map(float, line.split()[1:])]
             except StopIteration:
                 break
         try:
             next(part)
         except StopIteration:
             break
     for i in range(n):
         for j in range(i):
             hessian[j, i] = hessian[i, j]
     return hessian
示例#14
0
def get_geometry_from_bagel(iterable):
    LR = ListReader(iterable)
    LR.go_by_keys("*** Geometry ***")
    LR.get_next_lines(1)
    part_of_file = LR.get_all_by_keys(
        " The gradients will be computed analytically.")
    coord = []
    for line in part_of_file:
        line = line.replace(",", "")
        if len(line.split()) < 4:
            break
        coord.extend([float(i) for i in line.split()[7:10]])
    LR.go_by_keys("* Nuclear energy gradient")
    LR.get_next_lines(1)
    part_of_file = LR.get_all_by_keys("* Gradient computed with")
    grads = []
    for line in part_of_file:
        line = line.replace("\n", "")
        if " x " in line or " y " in line or " z " in line:
            grads.append(float(line.replace("\n", "").split()[-1]))
    return np.array(coord), np.array(grads)