Пример #1
0
def read_basis_set_file(file_input_basis, nuclei_array):
    """Reads a GAMESS-UK formatted gaussian basis set file using a list of nuclei objects.

    Parameters
    ----------
    file_input_basis : str
    nuclei_array : List[Nuclei]

    Returns
    -------
    basis_array : List[Basis]

    See Also
    --------
    expand_basis_set : function for expanding L, P, D and higher functions

    """
    file_input_basis = os.path.join('../../', 'basissets/' + file_input_basis)
    basis_array = []
    for a in range(len(nuclei_array)):
        file = open(file_input_basis, 'r')
        lines = file.read().replace('\n', ':')
        file.close()

        regex = nuclei_array[a].element + '.*?#'  # e.g. regex = CARBON.*?#
        lines = ' '.join(lines.split()) + '#'  # remove whitespace and add '#' for last element
        lines = re.search(regex, lines).group(0)  # return string from regex
        lines = re.split(':', lines.replace(': ', ':'))  # create list from colon separated string
        lines = lines[1:len(lines) - 2]

        i = 0
        input1 = input2 = []
        for line in lines:
            if any(letter in line for letter in ('S', 'L', 'P', 'D')):
                if i == 1:
                    input1.append(input2)
                    input2 = [line[0]]
                else:
                    i = 1
                    input2 = [line[0]]
            else:
                input2.append([float(b) for b in line.split()])
        input1.append(input2)

        # basis set file data is now in a more convenient form for expand_basis_set to process
        basis_array_from_fact = expand_basis_set(input1, nuclei_array[a].coordinates)
        basis_array += basis_array_from_fact

    return basis_array
 def test_expand_basis_returns_a_array_of_coefficients_for_a_s_type_gaussian(self):
     array = expand_basis_set([['S', [0.15432897, 3.42525091]]], (0, 0, 0.7316))
     self.assertEquals(array[0].integral_exponents, (0, 0, 0))
     self.assertEquals(array[0].coordinates, (0, 0, 0.7316))
     self.assertEquals(array[0].primitive_gaussian_array[0].contraction, 0.15432897)
     self.assertEquals(array[0].primitive_gaussian_array[0].exponent, 3.42525091)