Example #1
0
 def launch_opt_jobs(self):
     """
     Mimicing DihedralScanner.launch_opt_jobs,
     """
     assert hasattr(self, 'next_jobs') and hasattr(
         self, 'current_finished_job_results')
     while len(self.opt_queue) > 0:
         m, from_grid_id, to_grid_id = self.opt_queue.pop()
         # check if this job already exists
         m_geo_key = get_geo_key(m.xyzs[0])
         if m_geo_key in self.task_cache[to_grid_id]:
             final_geo, final_energy, job_folder = self.task_cache[
                 to_grid_id][m_geo_key]
             result_m = Molecule()
             result_m.elem = list(m.elem)
             result_m.xyzs = [final_geo]
             result_m.qm_energies = [final_energy]
             result_m.build_topology()
             grid_id = self.get_dihedral_id(result_m,
                                            check_grid_id=to_grid_id)
             if grid_id is None:
                 print(
                     f"Cached result from {job_folder} is ignored because optimized geometry is far from grid id {to_grid_id}"
                 )
             else:
                 self.current_finished_job_results.push((result_m, grid_id),
                                                        priority=job_folder)
         else:
             # append the job to self.next_jobs, which is the output of torsiondrive-API
             self.next_jobs[to_grid_id].append(m.xyzs[0].copy())
Example #2
0
    def rebuild_task_cache(self, grid_status):
        """
        Take a dictionary of finished optimizations, rebuild task_cache dictionary
        This function mimics the DihedralScanner.restore_task_cache()

        Parameters:
        ------------
        grid_status = dict(), key is the grid_id, value is a list of job_info. Each job_info is a tuple of (start_geo, end_geo, end_energy).
            * Note: The order of the job_info is important when reproducing the same scan procedure.

        Returns: None
        ------------
        Upon finish, the new folder 'opt_tmp' will be created, with many empty folders corrsponding to the finished jobs.
        self.task_cache will be populated with correct information for repreducing the entire scan process.
        """
        for grid_id, job_info_list in grid_status.items():
            tname = 'gid_' + '_'.join('%+04d' % gid for gid in grid_id)
            tmp_folder_path = os.path.join(self.tmp_folder_name, tname)
            for i_job, job_info in enumerate(job_info_list):
                job_path = os.path.join(tmp_folder_path, str(i_job + 1))
                (start_geo, end_geo, end_energy) = job_info
                job_geo_key = get_geo_key(start_geo)
                self.task_cache[grid_id][job_geo_key] = (end_geo, end_energy,
                                                         job_path)
Example #3
0
    def rebuild_task_cache(self, grid_status):
        """
        Take a dictionary of finished optimizations, rebuild task_cache dictionary
        This function mimics the DihedralScanner.restore_task_cache()

        Parameters
        -----------
        grid_status = dict(), key is the grid_id, value is a list of job_info. Each job_info is a tuple of (start_geo, end_geo, end_energy).
            * Note: The order of the job_info is important when reproducing the same scan procedure.

        Notes
        -----
        Upon finish, self.task_cache will be populated with correct information for repreducing the entire scan process, i.e.
        self.task_cache = {(30,-60): {geo_key: (final_geo, final_energy, final_gradient, job_folder)}}
        """
        for grid_id, job_info_list in grid_status.items():
            tname = 'gid_' + '_'.join('%+04d' % gid for gid in grid_id)
            tmp_folder_path = os.path.join(self.tmp_folder_name, tname)
            for i_job, job_info in enumerate(job_info_list):
                job_path = os.path.join(tmp_folder_path, str(i_job + 1))
                (start_geo, end_geo, end_energy) = job_info
                job_geo_key = get_geo_key(start_geo)
                self.task_cache[grid_id][job_geo_key] = (end_geo, end_energy,
                                                         None, job_path)