def get_localEnv(frame, centerIdx, cutoff, onlyDict=False): ''' Get the local atomic environment around an atom in an atomic frame. :param frame: ase or quippy Atoms object :param centerIdx: int Index of the local environment center. :param cutoff: float Cutoff radius of the local environment. :return: ase Atoms object Local atomic environment. The center atom is in first position. ''' import ase.atoms import quippy.atoms from ase.neighborlist import NeighborList from ase import Atoms as aseAtoms if isinstance(frame, quippy.atoms.Atoms): atoms = qp2ase(frame) elif isinstance(frame, ase.atoms.Atoms): atoms = frame else: raise ValueError n = len(atoms.get_atomic_numbers()) nl = NeighborList([ cutoff / 2., ] * n, skin=0., sorted=False, self_interaction=False, bothways=True) nl.build(atoms) cell = atoms.get_cell() pbc = atoms.get_pbc() pos = atoms.get_positions() positions = [ pos[centerIdx], ] zList = atoms.get_atomic_numbers() numbers = [ zList[centerIdx], ] indices, offsets = nl.get_neighbors(centerIdx) # print offsets,len(atom.get_atomic_numbers()) for i, offset in zip(indices, offsets): positions.append(pos[i] + np.dot(offset, cell)) numbers.append(zList[i]) atomsParam = dict(numbers=numbers, cell=cell, positions=positions, pbc=pbc) if onlyDict: return atomsParam else: return aseAtoms(**atomsParam)
def _get_dispersion_params(self, atoms): self.alpha_ref, self.C6_ref, self.RvdW_ref = get_free_atom_data(\ atoms.get_chemical_symbols() ) self.alpha_ref = np.asarray(self.alpha_ref) self.C6_ref, self.RvdW_ref = np.asarray(self.C6_ref), np.asarray( self.RvdW_ref) if self.use_fractional_ionic_approach: from ase.calculators.AlphaModel import AlphaModel from os.path import dirname dir_ref = dirname(__file__) + '/alpha_FI_refdata/' Z = atoms.get_atomic_numbers() if not hasattr(self, 'atomic_charges'): from ase.calculators.calculator import PropertyNotImplementedError try: q = atoms.get_charges() except (RuntimeError, PropertyNotImplementedError): msg = 'WARNING: Cannot get charges for fractional ionic approach from atoms object.\n' msg += ' Please, provide argument atomic_charges. Using neutral atoms for now...' print(msg) q = np.zeros_like(Z) else: q = np.asarray(self.atomic_charges) Npop_l = np.int64(Z - q) f_FI = Z - q - Npop_l a_FI = AlphaModel(filename=dir_ref + 'Model' + self.alpha_model + '.dat') a_dyn = np.zeros((self.n_omega_SCS + 1, self.n_atoms)) for i in range(self.n_atoms): fi = f_FI[i] ZNu, ZNl = (Z[i], Npop_l[i] + 1), (Z[i], Npop_l[i]) ZNul = [ZNu, ZNl] a_dyn[:,i] = fi * a_FI.GetAlpha(ZNu, omega=mbd_mod.omega_grid) + \ (1.-fi) * a_FI.GetAlpha(ZNl, omega=mbd_mod.omega_grid) self.C6_ref[i] = fi*fi * a_FI.GetC6(ZNu) + \ 2.*fi*(1.-fi) * a_FI.GetC6(ZNul) + \ (1.-fi)*(1.-fi)* a_FI.GetC6(ZNl) self.alpha_ref = a_dyn[0, :] self.a_div_a0 *= Z / (Z - q) self.alpha_dyn_TS = a_dyn * self.a_div_a0 self.alpha_0_TS = self.alpha_ref * self.a_div_a0 self.C6_TS = self.C6_ref * self.a_div_a0 * self.a_div_a0 if not self.use_fractional_ionic_approach: self.alpha_dyn_TS = mbd_mod.alpha_dynamic_ts_all('C', self.n_omega_SCS, \ self.alpha_0_TS, c6=self.C6_TS) if self.use_RvdW_from_alpha: self.RvdW_TS = 2.54 * self.alpha_0_TS**(1. / 7.) else: self.RvdW_TS = self.RvdW_ref * self.a_div_a0**(1. / 3.) self.omega_TS = mbd_mod.omega_eff(self.C6_TS, self.alpha_0_TS)
def dft_d_pbc(atoms, scaling_factor=0.75, interactionlist=None, interactionmatrix=None, cutoff_radius=DF_CUTOFF_RADIUS): """Main function making the D-G06 DFT-D correction available for systems with periodic boundary conditions. Applies the lattice summation defined in "lattice_sum" to the intra- and inter-cell evaluation of the D-G06 correction carried out in "d_g06_cell". >>> HCldim = Atoms('Cl2') >>> x1 = ( 1.65, 0, -0.01) >>> x2 = (-1.65, 0, 0.01) >>> HCldim.set_positions([x1,x2]) >>> HCldim.set_atomic_numbers([ 17, 17]) >>> HCldim.set_cell([(10.0, 0.0, 0.0), (0.0, 10.0, 0.0), (0.0, 0.0, 3.3)]) >>> HCldim.set_pbc([False,]*3) >>> dft_d_pbc(HCldim) (-0.016281380498314325, array([[-0.01672876, 0. , 0.00010139], [ 0.01672876, 0. , -0.00010139]])) >>> iso_c, iso_g = dft_d_iso(HCldim) >>> pbc_c, pbc_g = dft_d_pbc(HCldim) >>> iso_c == pbc_c, iso_g == pbc_g (True, array([[ True, True, True], [ True, True, True]], dtype=bool)) """ # # Obtain data about system atom_numbers = atoms.get_atomic_numbers() positions = atoms.get_positions() periodic_directions = atoms.get_pbc() elem_cell = atoms.get_cell() # # Number of atoms within a single copy N_atoms = len(positions) # # Check input i.e. if interactionlist and interactionmatrix are set properly interactionlist, interactionmatrix = check_interaction_group_input(N_atoms, interactionlist, interactionmatrix) # # Start with Calculation # Get DFT-D parameters params = [d_g06_parameters(ind_1) for ind_1 in atom_numbers] # # Define function "func" as "d_g06" for the lattice summation done in "lattice_sum" def func(t): return d_g06_cell(N_atoms, params, positions, interactionlist, interactionmatrix, cutoff_radius, t_vec=t) # # Call lattice summation with function "d_g06_cell" dispersion_correction, gradient_contribution = lattice_sum( func, positions, elem_cell, periodic_directions, cutoff_radius ) # # Scale dispersion correction and forces according to used XC-functional dispersion_correction = dispersion_correction * scaling_factor gradient_contribution = gradient_contribution * scaling_factor # return dispersion_correction, gradient_contribution
def dft_d_iso(atoms, scaling_factor=0.75, interactionlist=None, interactionmatrix=None, cutoff_radius=DF_CUTOFF_RADIUS): """Main function making the D-G06 DFT-D correction available for isolated systems. Consists in the application of an intra-cell evaluation of the D-G06 correction carried out in "d_g06_cell". >>> HCldim = Atoms('Cl2') >>> x1 = ( 1.65, 0, -0.01) >>> x2 = (-1.65, 0, 0.01) >>> HCldim.set_positions([x1,x2]) >>> HCldim.set_atomic_numbers([ 17, 17]) >>> dft_d_pbc(HCldim) (-0.016281380498314325, array([[-0.01672876, 0. , 0.00010139], [ 0.01672876, 0. , -0.00010139]])) """ # # Obtain data about system atom_numbers = atoms.get_atomic_numbers() positions = atoms.get_positions() # # Number of atoms within a single copy N_atoms = len(positions) # # Check input i.e. if interactionlist and interactionmatrix are set properly interactionlist, interactionmatrix = check_interaction_group_input(N_atoms, interactionlist, interactionmatrix) interactionmatrix = np.array(interactionmatrix) # # Start with Calculation # Get DFT-D parameters params = [d_g06_parameters(ind_1) for ind_1 in atom_numbers] # # Define function "func" as "d_g06" for the lattice summation done in "lattice_sum" dispersion_correction, gradient_contribution = d_g06_cell( N_atoms, params, positions, interactionlist, interactionmatrix, cutoff_radius ) # # Scale dispersion correction and forces according to used XC-functional dispersion_correction = dispersion_correction * scaling_factor gradient_contribution = gradient_contribution * scaling_factor # return dispersion_correction, gradient_contribution
def initialize_sdc(self, atoms=None): """ Initialization of all parameters in the sedc-module. Here we initialize all parameters in order to successfully calculate with sdc_recode module. The priority of parameters is user > default > dummy. The bare minimum of required parameters is: * atoms [ ASE atoms-object of the system treated ] * sedc_n_groups [ integer, number of differently treated groups ] * sedc_groups [ array of integers, number of atoms per group ] * sedc_pbc_switches [ np.array of 6-dim vectors specifying the VdW contributions in A,B,C in positive and negative direction ] This has to be done after the creation of our calculator-object, because otherwise we do not have the atoms-module to calculate most of the required properties. """ for arg in self.valid_args: if hasattr(self, arg): # In order to avoid lengthy np-initialization in aims-script if (arg == 'sedc_pbc_g_switches'): setattr(sdc.sdc_recode, arg, eval('np.transpose(self.' + arg + ')')) elif (arg == 'sedc_tssurf_vfree_div_vbulk'): tmp_array = \ np.array(([1] * atoms.get_number_of_atoms()), np.float64) species = [] n_species = 0 for atom in atoms: species_i = atom.number if species_i not in species: species.append(species_i) n_species += 1 species.sort() for i,a in enumerate(atoms): for ss, s in enumerate(species): if s==a.number: tmp_array[i] = \ self.sedc_tssurf_vfree_div_vbulk[ss] sdc.sdc_recode.sedc_tssurf_vfree_div_vbulk = \ tmp_array else: setattr(sdc.sdc_recode, arg, eval('self.' + arg)) elif arg in self.default_parameters: setattr(sdc.sdc_recode, arg, self.default_parameters[arg]) else: if (arg == 'internal_cart_coord'): sdc.sdc_recode.internal_cart_coord = \ atoms.get_positions().transpose().copy() elif (arg == 'sedc_cart_coord'): sdc.sdc_recode.sedc_cart_coord = \ atoms.get_positions().transpose().copy() elif (arg == 'sedc_cell_vectors'): sdc.sdc_recode.sedc_cell_vectors = \ atoms.get_cell().transpose().copy() elif (arg == 'sedc_species'): sdc.sdc_recode.sedc_species = \ atoms.get_atomic_numbers().copy() elif (arg == 'sedc_n_ions'): sdc.sdc_recode.sedc_n_ions = \ atoms.get_number_of_atoms() elif (arg == 'sedc_pbc_g_fold'): sdc.sdc_recode.sedc_pbc_g_fold = [0] * self.sedc_n_groups elif (arg == 'sedc_ts_veff_div_vfree'): if not self.hirshvolrat_is_set: sdc.sdc_recode.sedc_ts_veff_div_vfree = \ np.array(([1] * atoms.get_number_of_atoms()), np.float64) elif (arg == 'sedc_tssurf_vfree_div_vbulk'): sdc.sdc_recode.sedc_tssurf_vfree_div_vbulk = \ np.array(([1] * atoms.get_number_of_atoms()), np.float64) elif (arg == 'sedc_skip_atom'): sdc.sdc_recode.sedc_skip_atom = \ np.array(([-1] * atoms.get_number_of_atoms()), np.float64) elif (arg == 'sedc_pbc_g_only_intra'): sdc.sdc_recode.sedc_pbc_g_only_intra = \ [0] * self.sedc_n_groups elif (arg == 'sedc_pbc_g_cells'): sdc.sdc_recode.sedc_pbc_g_cells = \ np.tile(atoms.get_cell().transpose().copy(), (1, self.sedc_n_groups)) elif (arg == 'sedc_pbc_g_skip'): sdc.sdc_recode.sedc_pbc_g_skip = [0] * self.sedc_n_groups else: print("You've been sloppy my friend. :) Variable:", arg, \ " does not exist!")