def principalAxes(self, **kwargs): weight = [qtk.n2m(elem) for elem in self.type_list] center = self.getCenterOfMass() self.center(center) inertia = np.zeros([3,3]) I0 = 0 for i in range(3): I0 = I0 + sum(self.R[:,i]**2 * weight) for i in range(3): coord_i = self.R[:,i] inertia[i,i] = I0 - sum(coord_i**2 * weight) for j in range(i+1,3): coord_j = self.R[:,j] inertia[i,j] = -sum(coord_i*coord_j*weight) inertia[j,i] = inertia[i,j] I, U = np.linalg.eigh(inertia) self.shift(center) #return sorted(I,reverse=True), U[I.argsort()[::-1]] return I, U
def principalAxes(self, order='ascent', **kwargs): weight = [qtk.n2m(elem) for elem in self.type_list] center = self.getCenterOfMass() self.center(center) inertia = np.zeros([3,3]) I0 = 0 for i in range(3): I0 = I0 + sum(self.R[:,i]**2 * weight) for i in range(3): coord_i = self.R[:,i] inertia[i,i] = I0 - sum(coord_i**2 * weight) for j in range(i+1,3): coord_j = self.R[:,j] inertia[i,j] = -sum(coord_i*coord_j*weight) inertia[j,i] = inertia[i,j] I, U = np.linalg.eigh(inertia) self.shift(center) if order == 'ascent': return I, U else: return sorted(I,reverse=True), U[I.argsort()[::-1]]
def writeInp(name=None, **setting): inp, molecule = \ PlanewaveInput.write(self, name, **setting) molecule.sort() type_index = molecule.index type_list = molecule.type_list pp_files = [] self.content['system']['nat'] = molecule.N self.content['system']['ntyp'] = len(type_index) - 1 if setting['full_kmesh']: self.content['system']['nosym'] = True self.content['system']['noinv'] = True if 'restart' in setting and setting['restart']: self.content['control']['restart_mode'] = 'restart' if 'save_density' in setting and setting['save_density']: self.content['control']['wf_collect'] = True if 'save_wf' in setting and setting['save_wf']: self.content['control']['wf_collect'] = True if 'print_force' not in setting or not setting['print_force']: self.content['control']['tprnfor'] = True if not setting['periodic']: self.content['system']['assume_isolated'] = 'mt' if 'exx' in setting and setting['exx'] == 'anisotropic': self.content['system']['exxdiv_treatment'] = 'vcut_ws' self.content['system']['ecutvcut'] = 0.7 self.content['system']['x_gamma_extrapolation'] = False if molecule.charge != 0: self.content['system']['tot_charge'] = molecule.charge if molecule.multiplicity != 1: self.content['system']['nspin'] = 2 diff = molecule.multiplicity - 1 self.content['system']['tot_magnetization'] = diff if 'theory' in setting: if self.setting['theory'] in dft_dict: self.content['system']['input_dft'] = \ dft_dict[self.setting['theory']] else: self.content['system']['input_dft'] = self.setting['theory'] if 'scf_step' in setting: self.content['electrons']['electron_maxstep'] =\ setting['scf_step'] if 'ks_states' in setting and setting['ks_states']: vs = int(round(self.molecule.getValenceElectrons() / 2.0)) self.content['system']['nbnd'] = setting['ks_states'] + vs if 'd_shell' in setting: for a in molecule.type_list: if a in setting['d_shell'] and qtk.n2ve(a) < 10: self.content['system']['nbnd'] += 5 if 'symmetry' in setting: if setting['symmetry'] == 'fcc': self.content['system']['ibrav'] = 2 setting['fractional_coordinate'] = True dm = ['A', 'B', 'C', 'cosBC', 'cosAC', 'cosAB'] for i in range(6): self.content['system'][dm[i]] = float(self .molecule.celldm[i]) for section_key in self.content.iterkeys(): section = '&' + section_key + '\n' inp.write(section) for key, value in self.content[section_key].iteritems(): if type(value) is str: entry = " %s = '%s',\n" % (key, value) elif type(value) is int: entry = ' %s = %d,\n' % (key, value) elif type(value) is float: entry = ' %s = %14.8E,\n' % (key, value) elif type(value) is bool: if value: entry = ' %s = .true.,\n' % key else: entry = ' %s = .false.,\n' % key inp.write(entry) inp.write('/\n') inp.write("ATOMIC_SPECIES\n") for a in range(len(type_index)-1): type_n = type_index[a+1] - type_index[a] PPStr = PPString(self, molecule, type_index[a], type_n, inp) stem, ext = os.path.splitext(PPStr) if ext != '.UPF': PPStr = PPStr + '.UPF' mass = qtk.n2m(type_list[type_index[a]]) inp.write(' %-3s % 6.3f %s\n' % \ (type_list[type_index[a]], mass, PPStr)) pp_files.append(PPStr) inp.write("\n") inp.write("ATOMIC_POSITIONS ") if self.content['system']['ibrav'] == 0: if not setting['fractional_coordinate']: inp.write("angstrom\n") R = molecule.R else: inp.write("crystal\n") R = molecule.R_scale else: inp.write("\n") R = molecule.R_scale for a in range(len(type_list)): inp.write(' %-3s' % type_list[a]) for i in range(3): inp.write(' % 12.8f' % R[a, i]) inp.write("\n") inp.write("\n") if 'kmesh' in setting and setting['kmesh']: inp.write("K_POINTS automatic\n") for k in setting['kmesh']: inp.write(" %d" % k) for s in range(3): inp.write(" 0") inp.write('\n\n') if 'save_restart' in setting and setting['save_restart']: inp.write("ALCHEMY reference\n\n") if 'restart' in setting and setting['restart']: if 'scf_step' in setting and setting['scf_step'] == 1: inp.write("ALCHEMY prediction\n\n") if self.content['system']['ibrav'] == 0: inp.write("CELL_PARAMETERS angstrom\n") if 'lattice' not in self.setting: self.celldm2lattice() lattice_vec = self.setting['lattice'] for vec in lattice_vec: for component in vec: inp.write(' % 11.6f' % component) inp.write('\n') for pp in pp_files: pp_file = os.path.join(qtk.setting.espresso_pp, pp) if pp not in inp.dependent_files: inp.dependent_files.append(pp_file) if 'no_cleanup' in setting and setting['no_cleanup']: inp.close(no_cleanup=True) else: inp.close() return inp
def writeInp(name=None, **setting): inp, molecule = \ PlanewaveInput.write(self, name, **setting) molecule.sort() type_index = molecule.index type_list = molecule.type_list pp_files = [] self.content['system']['nat'] = molecule.N self.content['system']['ntyp'] = len(type_index) - 1 if setting['full_kmesh']: self.content['system']['nosym'] = True self.content['system']['noinv'] = True if 'restart' in setting and setting['restart']: self.content['control']['restart_mode'] = 'restart' if 'save_density' in setting and setting['save_density']: self.content['control']['wf_collect'] = True if 'save_wf' in setting and setting['save_wf']: self.content['control']['wf_collect'] = True if 'print_force' not in setting or not setting['print_force']: self.content['control']['tprnfor'] = True if not setting['periodic']: self.content['system']['assume_isolated'] = 'mt' if 'exx' in setting and setting['exx'] == 'anisotropic': self.content['system']['exxdiv_treatment'] = 'vcut_ws' self.content['system']['ecutvcut'] = 0.7 self.content['system']['x_gamma_extrapolation'] = False if molecule.charge != 0: self.content['system']['tot_charge'] = molecule.charge if molecule.multiplicity != 1: self.content['system']['nspin'] = 2 diff = molecule.multiplicity - 1 self.content['system']['tot_magnetization'] = diff if 'theory' in setting: if self.setting['theory'] in dft_dict: self.content['system']['input_dft'] = \ dft_dict[self.setting['theory']] else: self.content['system']['input_dft'] = self.setting[ 'theory'] if 'scf_step' in setting: self.content['electrons']['electron_maxstep'] =\ setting['scf_step'] if 'ks_states' in setting and setting['ks_states']: vs = int(round(self.molecule.getValenceElectrons() / 2.0)) self.content['system']['nbnd'] = setting['ks_states'] + vs if 'd_shell' in setting: for a in molecule.type_list: if a in setting['d_shell'] and qtk.n2ve(a) < 10: self.content['system']['nbnd'] += 5 if 'symmetry' in setting: if setting['symmetry'] == 'fcc': self.content['system']['ibrav'] = 2 setting['fractional_coordinate'] = True dm = ['A', 'B', 'C', 'cosBC', 'cosAC', 'cosAB'] for i in range(6): self.content['system'][dm[i]] = float( self.molecule.celldm[i]) for section_key in self.content.iterkeys(): section = '&' + section_key + '\n' inp.write(section) for key, value in self.content[section_key].iteritems(): if type(value) is str: entry = " %s = '%s',\n" % (key, value) elif type(value) is int: entry = ' %s = %d,\n' % (key, value) elif type(value) is float: entry = ' %s = %14.8E,\n' % (key, value) elif type(value) is bool: if value: entry = ' %s = .true.,\n' % key else: entry = ' %s = .false.,\n' % key inp.write(entry) inp.write('/\n') inp.write("ATOMIC_SPECIES\n") for a in range(len(type_index) - 1): type_n = type_index[a + 1] - type_index[a] PPStr = PPString(self, molecule, type_index[a], type_n, inp) stem, ext = os.path.splitext(PPStr) if ext != '.UPF': PPStr = PPStr + '.UPF' mass = qtk.n2m(type_list[type_index[a]]) inp.write(' %-3s % 6.3f %s\n' % \ (type_list[type_index[a]], mass, PPStr)) pp_files.append(PPStr) inp.write("\n") inp.write("ATOMIC_POSITIONS ") if self.content['system']['ibrav'] == 0: if not setting['fractional_coordinate']: inp.write("angstrom\n") R = molecule.R else: inp.write("crystal\n") R = molecule.R_scale else: inp.write("\n") R = molecule.R_scale for a in range(len(type_list)): inp.write(' %-3s' % type_list[a]) for i in range(3): inp.write(' % 12.8f' % R[a, i]) inp.write("\n") inp.write("\n") if 'kmesh' in setting and setting['kmesh']: inp.write("K_POINTS automatic\n") for k in setting['kmesh']: inp.write(" %d" % k) for s in range(3): inp.write(" 0") inp.write('\n\n') if 'save_restart' in setting and setting['save_restart']: inp.write("ALCHEMY reference\n\n") if 'restart' in setting and setting['restart']: if 'scf_step' in setting: if setting['scf_step'] != 1: qtk.warning('alchemy with optimization...') inp.write("ALCHEMY prediction\n\n") if self.content['system']['ibrav'] == 0: inp.write("CELL_PARAMETERS angstrom\n") if 'lattice' not in self.setting: self.celldm2lattice() lattice_vec = self.setting['lattice'] for vec in lattice_vec: for component in vec: inp.write(' % 11.6f' % component) inp.write('\n') for pp in pp_files: pp_file = os.path.join(qtk.setting.espresso_pp, pp) if pp not in inp.dependent_files: inp.dependent_files.append(pp_file) if 'no_cleanup' in setting and setting['no_cleanup']: inp.close(no_cleanup=True) else: inp.close() return inp
def getCenterOfMass(self): mass_list = [qtk.n2m(elem) for elem in self.type_list] weighted = self.R * np.array(mass_list).reshape([self.N,1]) return np.sum(weighted, axis=0)/float(sum(mass_list))