Пример #1
0
class AOForceOutputFile(object):
    def __init__(self, filename='aoforce.out'):
        self.filename = filename
        self.modes = None

    def read(self, mol):
        natoms = mol.natoms
        self.modes = VibModes(3 * natoms, mol)

        f = file(self.filename, 'r')
        lines = f.readlines()
        f.close()

        start = -1
        end = -1
        for i, l in enumerate(lines):
            if 'NORMAL MODES and VIBRATIONAL FREQUENCIES' in l:
                start = i
            elif (start > -1) and ('zero point VIBRATIONAL energy' in l):
                end = i
                break

        if start == -1:
            raise Exception('dipole gradients not found in control file')

        lines = lines[start + 1:end]

        freqlines = [
            l[14:] for l in lines if l.strip().startswith('frequency')
        ]
        freqs = ' '.join(freqlines).replace('i', '-')
        freqs = numpy.array([float(f) for f in freqs.split()])
        self.modes.set_freqs(freqs)

        masslines = [
            l[22:] for l in lines if l.strip().startswith('reduced mass')
        ]
        redmass = ' '.join(masslines)
        redmass = numpy.array([float(f) for f in redmass.split()])

        lines = [l[18:] for l in lines]
        lines = [
            l[2:] for l in lines
            if l.startswith('x') or l.startswith('y') or l.startswith('z')
        ]

        normalmodes = numpy.zeros((3 * natoms, 3 * natoms))

        ncol = len(lines[0].split())
        icol = -ncol
        for i, l in enumerate(lines):
            irow = i % (3 * natoms)

            if irow == 0:
                icol += ncol
            else:
                line = [float(fl) for fl in l.split()]
                normalmodes[icol:icol + ncol, irow] = line

        self.modes.set_modes_c(normalmodes)
Пример #2
0
    def read_hessian(self, mol):
        """
        Reading in the hessian martix.
        """
        natoms = mol.natoms
        self.hessian = numpy.zeros((natoms * 3, natoms * 3))
        self.modes = VibModes(3 * natoms, mol)

        f = open(self.filename, 'r')
        line = f.readline()
        while line != '':
            if 'SECOND DERIVATIVES' in line:
                break
            line = f.readline()
        if line == '':
            raise Exception('hessian not found in output file')
        line = f.readline()
        line = f.readline()
        line = f.readline()
        tmp = []  #temporary list for the lines
        while line != '':
            if line != ' \n':
                tmp.append(line)
                line = f.readline()
            else:
                break
        for i, l in enumerate(tmp):
            l = l.split()
            l.pop(0)
            tmp[i] = map(float, l)
        self.hessian = numpy.array(tmp)
        #symmetrizing the hessian
        self.hessian = -(self.hessian + self.hessian.transpose()) / 2.0
        f.close()
        for i, atmass in enumerate(mol.atmasses):
            self.hessian[:,
                         3 * i:3 * i + 3] = self.hessian[:, 3 * i:3 * i +
                                                         3] / math.sqrt(atmass)
            self.hessian[3 * i:3 * i +
                         3, :] = self.hessian[3 * i:3 * i +
                                              3, :] / math.sqrt(atmass)
        evals, evecs = numpy.linalg.eigh(self.hessian)
        # evals are in eV/Angs**2 *amu
        # convert to cm^-1 [evals are in Hartree / (Bohr**2 * amu) ]
        evals = evals * eV_in_Joule / (1e-10**2 * amu_in_kg
                                       )  # in J/(m*m*kg) = 1/s**2
        #print numpy.sqrt(abs(evals))/(2.0*math.pi)/cvel_ms*1e-2
        #print '-'*30
        for i in range(evals.size):
            if evals[i] > 0.0:
                evals[i] = math.sqrt(evals[i])
            else:
                evals[i] = -math.sqrt(-evals[i])

        evals = evals / (2.0 * math.pi)  # frequency in 1/s
        evals = evals / cvel_ms * 1e-2  # wavenumber in 1/cm
        #numpy.set_printoptions(precision=4)
        #print evals
        self.modes.set_freqs(evals)
        self.modes.set_modes_mw(evecs.transpose())
Пример #3
0
    def read_hessian(self, mol):
        natoms = mol.natoms
        self.hessian = numpy.zeros((natoms * 3, natoms * 3))
        self.modes = VibModes(3 * natoms, mol)

        f = open(self.filename, 'r')
        lines = f.readlines()
        f.close()

        start = -1
        end = -1
        for i, l in enumerate(lines):
            if l.startswith('$hessian'):
                start = i
            elif (start > -1) and l.startswith('$'):
                end = i
                break

        if start == -1:
            raise Exception('dipole gradients not found in control file')

        lines = lines[start + 1:end]
        ncol = len(lines[0].split()) - 2
        lines = [l[6:] for l in lines]

        nrow = 3 * natoms / ncol
        if 3 * natoms % ncol: nrow = nrow + 1

        for i in range(3 * natoms):
            row = ' '.join(lines[i * nrow:(i + 1) * nrow])
            row = numpy.array([float(f) for f in row.split()])

            self.hessian[i, :] = row

        # mass-weight Hessian
        for i, atmass in enumerate(mol.atmasses):
            self.hessian[:,
                         3 * i:3 * i + 3] = self.hessian[:, 3 * i:3 * i +
                                                         3] / math.sqrt(atmass)
            self.hessian[3 * i:3 * i +
                         3, :] = self.hessian[3 * i:3 * i +
                                              3, :] / math.sqrt(atmass)

        evals, evecs = numpy.linalg.eigh(self.hessian)

        # convert to cm^-1 [evals are in Hartree / (Bohr**2 * amu) ]
        evals = evals * Hartree_in_Joule / (Bohr_in_Meter**2 * amu_in_kg
                                            )  # in J/(m*m*kg) = 1/s**2

        for i in range(evals.size):
            if evals[i] > 0.0:
                evals[i] = math.sqrt(evals[i])
            else:
                evals[i] = -math.sqrt(-evals[i])

        evals = evals / (2.0 * math.pi)  # frequency in 1/s
        evals = evals / cvel_ms * 1e-2  # wavenumber in 1/cm

        self.modes.set_freqs(evals)
        self.modes.set_modes_mw(evecs.transpose())
Пример #4
0
    def read(self, mol):
        f = file('snf_control', 'r')
        lines = f.readlines()
        f.close()

        for i, l in enumerate(lines):
            if l.startswith('$nummodes'):
                nmodes = int(l.split()[-1])
                start = i + 1

        natoms = mol.natoms

        self.modes = VibModes(nmodes, mol)

        normalmodes = numpy.zeros((nmodes, 3 * natoms))
        freqs = numpy.zeros((nmodes))

        for imode in range(nmodes):
            freqs[imode] = float(lines[start + imode * natoms].split()[0])
            for i in range(natoms):
                x, y, z = lines[start + imode * natoms + i].split()[-3:]
                normalmodes[imode, 3 * i:3 * i + 3] = [x, y, z]

        self.modes.set_modes_c(normalmodes)
        self.modes.set_freqs(freqs)
Пример #5
0
    def read(self, mol):
        f = file(self.filename, 'r')
        lines = f.readlines()
        f.close()

        for l in lines:
            if 'intensities-only-mode' in l:
                self.intonly = True

        first = 0
        last = 0
        for i, l in enumerate(lines):
            if (first == 0) and ('root no.' in l):
                first = i
            if 'Generate fake outputs for' in l:
                last = i
                break
            if 'W A R N I N G' in l:
                last = i - 1
                break
            if 'Raman Optical Activity properties for freq.' in l:
                self.lwl = float(l[46:57])

        if not self.intonly:
            natoms = mol.natoms
            self.modes = VibModes(3 * natoms - 6, mol)

            lines = lines[first:last]
            lines = [l for l in lines if not len(l.strip()) == 0]
            lines = [l for l in lines if not l.startswith('1')]

            normalmodes = numpy.zeros((3 * natoms - 6, 3 * natoms))
            freqs = numpy.zeros((3 * natoms - 6))

            ncol = len(lines[2][10:].split())

            icol = -ncol
            for i, l in enumerate(lines):
                irow = i % (3 * natoms + 2) - 2

                if irow == -2:
                    if not ('root' in l):
                        raise Exception(
                            'wrong number of lines for normal modes')
                    icol += ncol
                else:
                    line = [float(fl) for fl in l[10:].split()]

                    if irow == -1:
                        freqs[icol:icol + ncol] = line
                    else:
                        normalmodes[icol:icol + ncol, irow] = line

            self.modes.set_modes_mw(normalmodes)
            self.modes.set_freqs(freqs)
Пример #6
0
class AKIRAResults(Results):
    def __init__(self,
                 iterationsfile='akira_iterations.out',
                 coordfile='coord'):
        self.mol = VibToolsMolecule()

        self.iterationsfile = iterationsfile
        self.coordfile = coordfile

        self.modes = None
        self.irints = None

    def read(self):
        import numpy, re

        self.mol.read_from_coord(filename=self.coordfile)

        #read akira iterations
        f = open(self.iterationsfile)
        lines = f.readlines()
        f.close()
        for i, l in enumerate(lines):
            if re.search('Final results from module Davidson', l):
                start = i
        nbas = int(lines[start + 3].split()[-1])
        lines = lines[start + 8:start + 8 + nbas]
        modes = []
        for l in lines:
            spl = l.split()
            if spl[10] == 'YES':
                modes.append([float(spl[2]), float(spl[8])])

        self.modes = VibModes(len(modes), self.mol)
        self.modes.set_freqs(numpy.array([m[0] for m in modes]))
        self.irints = numpy.array([m[1] for m in modes])

    def get_ir_intensity(self):
        return self.irints
Пример #7
0
    def read(self):
        import numpy, re

        self.mol.read_from_coord(filename=self.coordfile)

        #read akira iterations
        f = open(self.iterationsfile)
        lines = f.readlines()
        f.close()
        for i, l in enumerate(lines):
            if re.search('Final results from module Davidson', l):
                start = i
        nbas = int(lines[start + 3].split()[-1])
        lines = lines[start + 8:start + 8 + nbas]
        modes = []
        for l in lines:
            spl = l.split()
            if spl[10] == 'YES':
                modes.append([float(spl[2]), float(spl[8])])

        self.modes = VibModes(len(modes), self.mol)
        self.modes.set_freqs(numpy.array([m[0] for m in modes]))
        self.irints = numpy.array([m[1] for m in modes])
Пример #8
0
class VASPoutput(object):
    """
    Class that handles VASP output (OUTCAR) file.
    """
    def __init__(self, filename='full-output.vasp'):
        """
        The constructor of VASPoutput.
        """
        self.filename = filename
        self.dipgrad = None
        self.hessian = None
########## UPDATE below

    def read(self, mol):
        """
        Reading in the output file
        """
        natoms = mol.natoms
        self.dipgrad = numpy.zeros((natoms, 3, 3))
        f = open('full-output.vasp', 'r')
        line = f.readline()
        while line != '':
            if 'BORN EFFECTIVE CHARGES' in line:
                break
            line = f.readline()
        if line == '':
            raise Exception('Born effective charges not found in output file')
        line = f.readline()
        line = f.readline()
        line = f.readline()
        bec = []
        ion = []
        while line != '' and line != '\n':
            if 'ion' not in line:
                line = map(float, line.split()[1:])
                ion.append(line)
                line = f.readline()
            else:
                bec.append(ion)
                ion = []
                line = f.readline()
        bec.append(ion)
        ion = []
        self.dipgrad = numpy.array(bec)
        print self.dipgrad.shape
        f.close()

        #dipgrad = ' '.join(lines[start+1:end]).replace('D', 'E').replace('d', 'E').split()
        #self.dipgrad = numpy.array([float(d) for d in dipgrad])
        #self.dipgrad.shape = (natoms,3,3)


#### up to here

    def read_hessian(self, mol):
        """
        Reading in the hessian martix.
        """
        natoms = mol.natoms
        self.hessian = numpy.zeros((natoms * 3, natoms * 3))
        self.modes = VibModes(3 * natoms, mol)

        f = open(self.filename, 'r')
        line = f.readline()
        while line != '':
            if 'SECOND DERIVATIVES' in line:
                break
            line = f.readline()
        if line == '':
            raise Exception('hessian not found in output file')
        line = f.readline()
        line = f.readline()
        line = f.readline()
        tmp = []  #temporary list for the lines
        while line != '':
            if line != ' \n':
                tmp.append(line)
                line = f.readline()
            else:
                break
        for i, l in enumerate(tmp):
            l = l.split()
            l.pop(0)
            tmp[i] = map(float, l)
        self.hessian = numpy.array(tmp)
        #symmetrizing the hessian
        self.hessian = -(self.hessian + self.hessian.transpose()) / 2.0
        f.close()
        for i, atmass in enumerate(mol.atmasses):
            self.hessian[:,
                         3 * i:3 * i + 3] = self.hessian[:, 3 * i:3 * i +
                                                         3] / math.sqrt(atmass)
            self.hessian[3 * i:3 * i +
                         3, :] = self.hessian[3 * i:3 * i +
                                              3, :] / math.sqrt(atmass)
        evals, evecs = numpy.linalg.eigh(self.hessian)
        # evals are in eV/Angs**2 *amu
        # convert to cm^-1 [evals are in Hartree / (Bohr**2 * amu) ]
        evals = evals * eV_in_Joule / (1e-10**2 * amu_in_kg
                                       )  # in J/(m*m*kg) = 1/s**2
        #print numpy.sqrt(abs(evals))/(2.0*math.pi)/cvel_ms*1e-2
        #print '-'*30
        for i in range(evals.size):
            if evals[i] > 0.0:
                evals[i] = math.sqrt(evals[i])
            else:
                evals[i] = -math.sqrt(-evals[i])

        evals = evals / (2.0 * math.pi)  # frequency in 1/s
        evals = evals / cvel_ms * 1e-2  # wavenumber in 1/cm
        #numpy.set_printoptions(precision=4)
        #print evals
        self.modes.set_freqs(evals)
        self.modes.set_modes_mw(evecs.transpose())
Пример #9
0
class SNFOutputFile(object):
    def __init__(self, filename='snf.out'):
        self.modes = None
        self.lwl = None
        self.filename = filename
        self.intonly = False

    def read(self, mol):
        f = file(self.filename, 'r')
        lines = f.readlines()
        f.close()

        for l in lines:
            if 'intensities-only-mode' in l:
                self.intonly = True

        first = 0
        last = 0
        for i, l in enumerate(lines):
            if (first == 0) and ('root no.' in l):
                first = i
            if 'Generate fake outputs for' in l:
                last = i
                break
            if 'W A R N I N G' in l:
                last = i - 1
                break
            if 'Raman Optical Activity properties for freq.' in l:
                self.lwl = float(l[46:57])

        if not self.intonly:
            natoms = mol.natoms
            self.modes = VibModes(3 * natoms - 6, mol)

            lines = lines[first:last]
            lines = [l for l in lines if not len(l.strip()) == 0]
            lines = [l for l in lines if not l.startswith('1')]

            normalmodes = numpy.zeros((3 * natoms - 6, 3 * natoms))
            freqs = numpy.zeros((3 * natoms - 6))

            ncol = len(lines[2][10:].split())

            icol = -ncol
            for i, l in enumerate(lines):
                irow = i % (3 * natoms + 2) - 2

                if irow == -2:
                    if not ('root' in l):
                        raise Exception(
                            'wrong number of lines for normal modes')
                    icol += ncol
                else:
                    line = [float(fl) for fl in l[10:].split()]

                    if irow == -1:
                        freqs[icol:icol + ncol] = line
                    else:
                        normalmodes[icol:icol + ncol, irow] = line

            self.modes.set_modes_mw(normalmodes)
            self.modes.set_freqs(freqs)

    def read_mat(self, id_string):
        """Read in a matrix from the snf.out file, starting with the id_string.
        
        The matrix in the snf.out file should have the following form (only for the dipole gradients):
        
                    1            2               3
        1: dmu_x / dx   dmu_x / dy      dmu_x / dz
        2: dmu_y / dx   dmu_y / dy      dmu_y / dz     # Atom 1
        3: dmu_z / dx   dmu_z / dy      dmu_z / dz
        
                    4            5               6
        1: dmu_x / dx   dmu_x / dy      dmu_x / dz
        2: dmu_y / dx   dmu_y / dy      dmu_y / dz     # Atom 2
        3: dmu_z / dx   dmu_z / dy      dmu_z / dz

        etc.
        
        put one piece from the button to the right of the previous on and you get a 3 x 3*nr_atoms matrix
        but I want to work with a 3*nr_atoms x 3
        """

        f = file(self.filename, 'r')

        # Little hack to assure that you find the right polarizabilities (length vs. velocity representation)
        vel = False
        if "velocity" in id_string:
            vel = True
        while (True):
            line = f.readline()
            if line == "":
                raise Exception("Could not find " + id_string + "!!!")
            if id_string in line:
                # Make sure that you don't get the velocity representation instead of the length rep.
                if (not vel) and ("velocity" in line):
                    continue
                break

        # Get the header
        line = f.readline()
        columns = int(line.split()[5])
        num_rows = int(line.split()[9])
        i = 0
        matrix = numpy.zeros((num_rows, columns))

        # How is the matrix diplayed? Usually disp_col = 3
        line = f.readline()
        disp_col = len(line.split())

        row = 1
        while (i < num_rows):
            line = f.readline()
            beginning = str(row) + ":"
            if beginning in line:
                matrix[i:(i + disp_col),
                       row - 1] = [float(fl) for fl in line.split()[1:4]]
                if row == columns:
                    row = 1
                    i += disp_col
                else:
                    row += 1

        f.close()

        return matrix

    def read_derivatives(self, mol):
        self.dipole = self.read_mat("gradient of dipole moments").reshape(
            mol.natoms, 3, 3)
        self.pollen = self.read_mat(
            "gradient of polarizability tensor").reshape(mol.natoms, 3, 8)
        self.polvel = self.read_mat(
            "gradient of polarizability tensor (velocity representation)"
        ).reshape(mol.natoms, 3, 8)

        self.gtenlen = self.read_mat("gradient of G/LAO tensor").reshape(
            mol.natoms, 3, 9)
        self.gtenvel = self.read_mat("gradient of G/AO tensor").reshape(
            mol.natoms, 3, 9)

        self.aten = self.read_mat("gradient of A tensor").reshape(
            mol.natoms, 3, 27)