def get_result_directory_for_shell(self, nn, ll): resdir = self._resultdir_for_nl.get((nn, ll), None) if resdir is None: msg = 'No result directory for shell {:s}'.format( sc.shell_ind_to_name(nn, ll)) raise sc.SkgenException(msg) return resdir
def find_or_run_calculation(self): resultdirs = [] resultdir_for_nl = {} previous_calc_dirs = ssc.get_matching_subdirectories( self._onecenter_searchdirs, ssc.COMPRESSION_WORKDIR_PREFIX) for shells, myinput in self._shells_and_inputs: shellnames = [sc.shell_ind_to_name(nn, ll) for nn, ll in shells] LOGGER.info('Processing compression for shell(s) {}'.format( ' '.join(shellnames))) resultdir = myinput.get_first_dir_with_matching_signature( previous_calc_dirs) recalculation_needed = not resultdir if recalculation_needed: resultdir = ssc.create_onecenter_workdir( self._builddir, ssc.COMPRESSION_WORKDIR_PREFIX, self._elem) LOGGER.info( 'Calculating compressed atom ' + sc.log_path(resultdir)) calculation = AtomCompressionCalculation(myinput) calculation.run(resultdir, self._onecenter_binary) else: LOGGER.info( 'Matching calculation found ' + sc.log_path(resultdir)) self._extract_results_if_not_present(myinput, shells, resultdir) if recalculation_needed: myinput.store_signature(resultdir) resultdirs.append(resultdir) for nn, ll in shells: resultdir_for_nl[(nn, ll)] = resultdir self._resultdirs = resultdirs self._resultdir_for_nl = resultdir_for_nl
def get_wavefunction(self, nn, ll): shellname = sc.shell_ind_to_name(nn, ll) try: wfc = self._result[shellname] except KeyError: msg = 'Missing wavefunction {}'.format(shellname) raise sc.SkgenException(msg) return wfc
def _override_with_homo_value(atomconfig, atomresult, values): shells = atomconfig.valenceshells homo_nl_up, homo_nl_down = atomresult.get_homo_nl() if np.any(homo_nl_up != homo_nl_down): msg = "Different h**o for spin up and down ({} vs. {})".format( sc.shell_ind_to_name(*homo_nl_up), sc.shell_ind_to_name(*homo_nl_down)) raise sc.SkgenException(msg) # H**o indices may be stored in a numpy array homo_nl = tuple(homo_nl_up) try: ind = shells.index(homo_nl) except IndexError: msg = "H**o shell {} not among valence shells".format( sc.shell_ind_to_name(*homo_nl)) raise sc.SkgenException(msg) return [ values[ind], ] * len(values)
def _extract_results_if_not_present(myinput, shells, resultdir): resultshelf = os.path.join(resultdir, ssc.WAVECOMP_RESULT_FILE) if sc.shelf_exists(resultshelf): return calculator = AtomCompressionResult(myinput.calculator) output = calculator.get_output(resultdir) resultdict = {} for nn, ll in shells: # Needs name as shelf allows only strings as keys shellname = sc.shell_ind_to_name(nn, ll) resultdict[shellname] = output.get_wavefunction012(0, nn, ll) sc.store_as_shelf(resultshelf, resultdict)
def _extract_results_if_not_present(myinput, occshells, resultdir): resultshelf = os.path.join(resultdir, ssc.DENSCOMP_RESULT_FILE) if sc.shelf_exists(resultshelf): return calculator = AtomCompressionResult(myinput.calculator) output = calculator.get_output(resultdir) result = { 'potentials': output.get_potentials(), 'density': output.get_density012() } for qn, _ in occshells: nn = qn[0] ll = qn[1] # needs name as shelf allows only strings as keys shellname = sc.shell_ind_to_name(nn, ll) result[shellname] = output.get_wavefunction012(0, nn, ll) sc.store_as_shelf(resultshelf, result)