Exemplo n.º 1
0
def get_freqs_intens(kf, set_intens_to_one=False):
    '''
	Function to get frequencies and intensities from result objects

	kf - path to KF file
	'''

    #load kffile
    kff = plams.KFFile(kf)
    #read freqs and intens from kffile

    try:
        freqs = kff.read_section('Freq Symmetry')['Frequencies_A']
        if set_intens_to_one:
            intens = [1 for _ in freqs]
        else:
            intens = kff.read_section('Freq Symmetry')['IR intensities_A']
    except:
        freqs = kff.read_section('Vibrations')['Frequencies[cm-1]']

        if set_intens_to_one:
            intens = [1 for _ in freqs]
        else:
            intens = kff.read_section('Vibrations')['Intensities[km/mol]']

    return np.asarray(freqs), np.asarray(intens)
Exemplo n.º 2
0
    def __init__(self,
                 settings: Optional[Settings],
                 molecule: Optional[plams.Molecule],
                 job_name: str,
                 dill_path: Union[None, str, os.PathLike] = None,
                 plams_dir: Union[None, str, os.PathLike] = None,
                 work_dir: Union[None, str, os.PathLike] = None,
                 status: str = 'done',
                 warnings: Optional[WarnMap] = None) -> None:
        # Load available property parser from yaml file.
        super().__init__(settings,
                         molecule,
                         job_name,
                         dill_path,
                         plams_dir=plams_dir,
                         status=status,
                         warnings=warnings)

        # Create a KF reader instance
        if work_dir is not None:
            # The t21 path has to be absolute: use workdir instead of plams_dir
            name_t21 = basename(normpath(work_dir))
            path_t21 = join(plams_dir, f'{name_t21}.t21')
            self.kf = plams.KFFile(path_t21)
        else:
            self.kf = None
Exemplo n.º 3
0
 def __init__(self, settings, molecule, job_name, path_t21, plams_dir=None,
              status='done', warnings=None):
     # Load available property parser from Json file.
     properties = package_properties['adf']
     super().__init__(settings, molecule, job_name, plams_dir=plams_dir,
                      properties=properties, status=status, warnings=warnings)
     # Create a KF reader instance
     self.kf = plams.KFFile(path_t21)
 def __init__(self, file):
     self.file = file
     self.rkf = plams.KFFile(file)
     self.nAtoms = self.rkf['Molecule%nAtoms']
     if type(self.rkf['Vibrations%Frequencies[cm-1]']) == float:
         self.nModes = 1
     else:
         self.nModes = len(self.rkf['Vibrations%Frequencies[cm-1]'])
Exemplo n.º 5
0
    def get_mo_coeffs(self):
        """Get the MO coefficient expressed in the BAS."""

        kf = plams.KFFile(self.out_file)
        nao = kf.read('Basis', 'naos')
        nmo = kf.read('A', 'nmo_A')
        self.mos = np.array(kf.read('A', 'Eigen-Bas_A'))
        self.mos = self.mos.reshape(nmo, nao).T
        self.mos = self.normalize_columns(self.mos)
        return self.mos
Exemplo n.º 6
0
 def __init__(self, settings, molecule, job_name, plams_dir=None,
              status='done', warnings=None):
     # Read available propiety parsers from a JSON file
     properties = package_properties['dftb']
     super().__init__(settings, molecule, job_name, plams_dir=plams_dir,
                      properties=properties, status=status, warnings=warnings)
     if plams_dir is not None:
         kf_filename = join(plams_dir, '{}.rkf'.format(job_name))
         # create a kf reader instance
         self.kf = plams.KFFile(kf_filename)
     else:
         self.kf = None
Exemplo n.º 7
0
def get_freqs_intens(result):
    '''
	Function to get frequencies and intensities from result objects

	results - plams.Results object
	'''

    #load kffile
    kff = plams.KFFile(result.KFPATH)
    #read freqs and intens from kffile
    freqs = kff.read_section('Vibrations')['Frequencies[cm-1]']
    if result.KFPATH.endswith('.rkf'):
        rotstr = kff.read_section('Vibrations')['RotationalStrength']
    else:
        rotstr = kff.read_section('Freq Symmetry')['VCD rotational strength_A']

    return freqs, rotstr
Exemplo n.º 8
0
def get_freqs_intens(kf):
    '''
	Function to get frequencies and intensities from result objects

	kf - path to KF file
	'''

    #load kffile
    kff = plams.KFFile(kf)
    #read freqs and intens from kffile

    try:
        freqs = kff.read_section('Freq Symmetry')['Frequencies_A']
        intens = kff.read_section('Freq Symmetry')['IR intensities_A']
    except:
        freqs = kff.read_section('Vibrations')['Frequencies[cm-1]']
        intens = kff.read_section('Vibrations')['Intensities[km/mol]']

    return freqs, intens
Exemplo n.º 9
0
    def __init__(self,
                 settings: Optional[Settings],
                 molecule: Optional[plams.Molecule],
                 job_name: str,
                 dill_path: Union[None, str, os.PathLike] = None,
                 plams_dir: Union[None, str, os.PathLike] = None,
                 work_dir: Union[None, str, os.PathLike] = None,
                 status: str = 'done',
                 warnings: Optional[WarnMap] = None) -> None:
        # Read available propiety parsers from a yaml file
        super().__init__(settings,
                         molecule,
                         job_name,
                         dill_path,
                         plams_dir=plams_dir,
                         status=status,
                         warnings=warnings)

        if plams_dir is not None:
            kf_filename = join(plams_dir, 'dftb.rkf')
            # create a kf reader instance
            self.kf = plams.KFFile(kf_filename)
        else:
            self.kf = None
Exemplo n.º 10
0
    def get_basis_data(self, kffile):
        """Save the basis information needed to compute the AO values."""

        if not os.path.isfile(kffile):
            raise FileNotFoundError(
                'File %s not found, ADF may have crashed, look into the plams_workdir directory'
                % kffile)
        kf = plams.KFFile(kffile)
        status = kf.read('General', 'termination status').strip()
        if status != 'NORMAL TERMINATION':
            log.info('  WARNING : ADF calculation terminated with status')
            log.info('          : %s' % status)
            log.info('          : Proceed with caution')

        basis = SimpleNamespace()

        basis.TotalEnergy = kf.read('Total Energy', 'Total energy')
        basis.radial_type = 'sto'
        basis.harmonics_type = 'cart'

        nao = kf.read('Basis', 'naos')
        nmo = kf.read('A', 'nmo_A')
        basis.nao = nao
        basis.nmo = nmo

        # number of bas per atom type
        nbptr = kf.read('Basis', 'nbptr')

        # number of atom per atom typ
        nqptr = kf.read('Geometry', 'nqptr')
        atom_type = kf.read('Geometry', 'atomtype').split()

        # number of bas per atom type
        nshells = np.array(
            [nbptr[i] - nbptr[i - 1] for i in range(1, len(nbptr))])

        # kx/ky/kz/kr exponent per atom type
        bas_kx = self.read_array(kf, 'Basis', 'kx')
        bas_ky = self.read_array(kf, 'Basis', 'ky')
        bas_kz = self.read_array(kf, 'Basis', 'kz')
        bas_kr = self.read_array(kf, 'Basis', 'kr')

        # bas exp/coeff/norm per atom type
        bas_exp = self.read_array(kf, 'Basis', 'alf')
        bas_norm = self.read_array(kf, 'Basis', 'bnorm')

        basis_nshells = []
        basis_bas_kx, basis_bas_ky, basis_bas_kz = [], [], []
        basis_bas_kr = []
        basis_bas_exp, basis_bas_norm = [], []

        for iat, at in enumerate(atom_type):

            number_copy = nqptr[iat + 1] - nqptr[iat]
            idx_bos = list(range(nbptr[iat] - 1, nbptr[iat + 1] - 1))

            basis_nshells += [nshells[iat]] * number_copy

            basis_bas_kx += list(bas_kx[idx_bos]) * number_copy
            basis_bas_ky += list(bas_ky[idx_bos]) * number_copy
            basis_bas_kz += list(bas_kz[idx_bos]) * number_copy
            basis_bas_kr += list(bas_kr[idx_bos]) * number_copy
            basis_bas_exp += list(bas_exp[idx_bos]) * number_copy
            basis_bas_norm += list(bas_norm[idx_bos]) * number_copy

        basis.nshells = basis_nshells
        basis.nao_per_atom = basis_nshells
        basis.index_ctr = np.arange(nao)
        basis.nctr_per_ao = np.ones(nao)

        basis.bas_kx = np.array(basis_bas_kx)
        basis.bas_ky = np.array(basis_bas_ky)
        basis.bas_kz = np.array(basis_bas_kz)
        basis.bas_kr = np.array(basis_bas_kr)

        basis.bas_exp = np.array(basis_bas_exp)
        basis.bas_coeffs = np.ones_like(basis_bas_exp)
        basis.bas_norm = np.array(basis_bas_norm)

        basis.atom_coords_internal = np.array(kf.read('Geometry',
                                                      'xyz')).reshape(-1, 3)

        # Molecular orbitals
        mos = np.array(kf.read('A', 'Eigen-Bas_A'))
        mos = mos.reshape(nmo, nao).T

        # normalize the MO
        # this is not needed !!!
        # mos = self.normalize_columns(mos)

        # orbital that take part in the rep
        npart = np.array(kf.read('A', 'npart')) - 1

        # create permutation matrix
        perm_mat = np.zeros((basis.nao, basis.nao))
        for i in range(basis.nao):
            perm_mat[npart[i], i] = 1.

        # reorder the basis function
        basis.mos = perm_mat @ mos

        return basis
Exemplo n.º 11
0
    def get_basis(self):
        """Get the basis information needed to compute the AO values."""

        kf = plams.KFFile(self.out_file)

        self.basis.radial_type = 'sto'
        self.basis.harmonics_type = 'cart'

        self.basis.nao = kf.read('Basis', 'naos')
        self.basis.nmo = kf.read('A', 'nmo_A')

        # number of bas per atom type
        nbptr = kf.read('Basis', 'nbptr')

        # number of atom per atom typ
        nqptr = kf.read('Geometry', 'nqptr')
        atom_type = kf.read('Geometry', 'atomtype').split()

        # number of bas per atom type
        nshells = np.array([nbptr[i] - nbptr[i - 1]
                            for i in range(1, len(nbptr))])

        # kx/ky/kz/kr exponent per atom type
        bas_kx = np.array(kf.read('Basis', 'kx'))
        bas_ky = np.array(kf.read('Basis', 'ky'))
        bas_kz = np.array(kf.read('Basis', 'kz'))
        bas_kr = np.array(kf.read('Basis', 'kr'))

        # bas exp/coeff/norm per atom type
        bas_exp = np.array(kf.read('Basis', 'alf'))
        bas_norm = np.array(kf.read('Basis', 'bnorm'))

        self.basis.nshells = []
        self.basis.bas_kx, self.basis.bas_ky, self.basis.bas_kz = [], [], []
        self.basis.bas_kr = []
        self.basis.bas_exp, self.basis.bas_norm = [], []

        for iat, at in enumerate(atom_type):

            number_copy = nqptr[iat + 1] - nqptr[iat]
            idx_bos = list(range(nbptr[iat] - 1, nbptr[iat + 1] - 1))

            self.basis.nshells += [nshells[iat]] * number_copy

            self.basis.bas_kx += list(bas_kx[idx_bos]) * number_copy
            self.basis.bas_ky += list(bas_ky[idx_bos]) * number_copy
            self.basis.bas_kz += list(bas_kz[idx_bos]) * number_copy
            self.basis.bas_kr += list(bas_kr[idx_bos]) * number_copy

            self.basis.bas_exp += list(bas_exp[idx_bos]) * number_copy
            self.basis.bas_norm += list(
                bas_norm[idx_bos]) * number_copy

        self.basis.nshells = np.array(self.basis.nshells)
        self.basis.bas_kx = np.array(self.basis.bas_kx)
        self.basis.bas_ky = np.array(self.basis.bas_ky)
        self.basis.bas_kz = np.array(self.basis.bas_kz)

        self.basis.bas_kr = np.array(self.basis.bas_kr)
        self.basis.bas_exp = np.array(self.basis.bas_exp)
        self.basis.bas_coeffs = np.ones_like(self.basis.bas_exp)
        self.basis.bas_norm = np.array(self.basis.bas_norm)

        self.basis.index_ctr = np.arange(self.basis.nao)
        self.basis.atom_coords_internal = np.array(
            kf.read('Geometry', 'xyz')).reshape(-1, 3)

        self.check_basis(self.basis)

        return self.basis
Exemplo n.º 12
0
    def run(self):
        """Run the calculation

        Raises:
            ValueError: [description]

        Returns:
            np.ndarray -- molecular orbital matrix
        """

        wd = ''.join(self.atoms) + '_' + self.basis_name
        t21_name = wd + '.t21'
        plams_wd = './plams_workdir'
        t21_path = os.path.join(plams_wd, os.path.join(wd, t21_name))

        if os.path.isfile(t21_name):

            print('Reusing previous calculation from ', t21_name)
            kf = plams.KFFile(t21_name)
            e = kf.read('Total Energy', 'Total energy')

        else:

            # init PLAMS
            plams.init()
            plams.config.log.stdout = -1
            plams.config.erase_workdir = True

            # create the molecule
            mol = plams.Molecule()
            for at, xyz in zip(self.atoms, self.atom_coords):
                mol.add_atom(plams.Atom(symbol=at, coords=tuple(xyz)))

            # settings in PLAMS
            sett = plams.Settings()
            sett.input.basis.type = self.basis_name.upper()
            sett.input.basis.core = 'None'
            sett.input.symmetry = 'nosym'
            sett.input.XC.HartreeFock = ''

            # correct unit
            if self.units == 'angs':
                sett.input.units.length = 'Angstrom'
            elif self.units == 'bohr':
                sett.input.units.length = 'Bohr'

            # total energy
            sett.input.totalenergy = True

            # run the ADF job
            job = plams.ADFJob(molecule=mol, settings=sett, name=wd)
            job.run()

            # read the energy from the t21 file
            e = job.results.readkf('Total Energy', 'Total energy')

            # make a copy of the t21 file
            shutil.copyfile(t21_path, t21_name)
            shutil.rmtree(plams_wd)

        # print energy
        print('== SCF Energy : ', e)
        self.out_file = t21_name
Exemplo n.º 13
0
 def __init__(self, file):
     self.file = file
     self.rkf = plams.KFFile(file)
     self.nAtoms = self.rkf['Geometry%nnuc']
Exemplo n.º 14
0
        else:
            sys.stdout.write("Please respond with 'yes' or 'no' "
                             "(or 'y' or 'n').\n")


#######################
## Loading variables ##
#######################

name, extension, rkfFiles = [], [], []

for file in os.listdir("."):
    if os.path.isfile(file):
        if file.endswith(".t21"):
            rkfFiles.append(TAPE21(file))
            t21 = plams.KFFile(file)
            name.append(os.path.splitext(file)[0])
            extension.append("TAPE21")

        elif file.endswith(".rkf"):
            rkfFiles.append(RKF(file))
            rkf = plams.KFFile(file)
            name.append(os.path.splitext(file)[0])
            extension.append("RKF")

##########################
## Interactive terminal ##
##########################

if not name:
    print("There are no RKF or T21 files in this directory.")