def add_one1(aggregate_id1, aggregate_id2, seeds1, seeds2, hm_orientations, method): """ """ seeds2 = seeds2[0] if check_stop_signal(): aggregator_logger.info("Function: add_one") return StopIteration aggregator_logger.info(' There are {} seed molecules'.format(len(seeds1))) cwd = os.getcwd() list_of_optimized_molecules = [] for seed_count, each_seed in enumerate(seeds1): if check_stop_signal(): print("Function: add_one") return print(' Seed: {}'.format(seed_count)) seed_id = "{:03d}".format(seed_count) seeds_home = 'seed_' + seed_id file_manager.make_directories(seeds_home) os.chdir(seeds_home) each_seed.mol_to_xyz('seed.xyz') seeds2.mol_to_xyz('monomer.xyz') mol_id = '{0}_{1}_{2}'.format(seed_id, aggregate_id1, aggregate_id2) all_orientations = tabu.generate_orientations(mol_id, seeds1[seed_count], seeds2, hm_orientations) not_converged = all_orientations[:] converged = [] for i in range(10): aggregator_logger.info( "Round %d of block optimizations with %d molecules" % (i + 1, len(not_converged))) if len(not_converged) == 0: break status_list = [ optimise(each_mol, method, max_cycles=350, convergence='loose') for each_mol in not_converged ] converged = [ n for n, s in zip(not_converged, status_list) if s is True ] list_of_optimized_molecules.extend(converged) not_converged = [ n for n, s in zip(not_converged, status_list) if s == 'CycleExceeded' ] not_converged = clustering.remove_similar(not_converged) os.chdir(cwd) print(list_of_optimized_molecules) if len(list_of_optimized_molecules) < 2: return list_of_optimized_molecules print(" Clustering") selected_seeds = clustering.choose_geometries(list_of_optimized_molecules) file_manager.make_directories('selected') for each_file in selected_seeds: status = optimise(each_file, method, max_cycles=350, convergence='normal') if status is True: xyz_file = 'seed_' + each_file.name[ 4: 7] + '/job_' + each_file.name + '/result_' + each_file.name + '.xyz' shutil.copy(xyz_file, 'selected/') else: selected_seeds.remove(each_file) return selected_seeds
def react(reactant_a, reactant_b, gamma_min, gamma_max, hm_orientations, method, site, proximity_factor): """Run reactor module. This is the outer loop generates all the orientations loop over all the gamma values optimize all orientations in each gamma after eliminating the products or failed geometries """ cwd = os.getcwd() reactor_logger.debug('Current working directory: {}'.format(cwd)) software = method['software'] print_header(gamma_max, gamma_min, hm_orientations, software) # prepare job directories product_dir = cwd + '/products' reactor_logger.debug('Product directory: {}'.format(product_dir)) file_manager.make_directories(product_dir) file_manager.make_directories('trial_geometries') os.chdir('trial_geometries') if site is None: all_orientations = tabu.generate_orientations('geom', reactant_a, reactant_b, hm_orientations) else: all_orientations = tabu.generate_guess_for_bonding( 'geom', reactant_a, reactant_b, site[0], site[1], hm_orientations) os.chdir(cwd) gamma_list = np.linspace(gamma_min, gamma_max, num=10, dtype=float) orientations_to_optimize = all_orientations[:] for gamma in gamma_list: reactor_logger.info(' Current gamma : {}'.format(gamma)) gamma_id = "%04d" % (int(gamma)) gamma_home = cwd + '/gamma_' + gamma_id file_manager.make_directories(gamma_home) os.chdir(gamma_home) optimized_molecules = optimize_all(gamma_id, gamma, orientations_to_optimize, product_dir, method) reactor_logger.info(" {} geometries from this gamma cycle".format( len(optimized_molecules))) if len(optimized_molecules) == 0: reactor_logger.info( "No orientations to be optimized for the next gamma cycle.") return if len(optimized_molecules) == 1: orientations_to_optimize = optimized_molecules[:] else: orientations_to_optimize = clustering.remove_similar( optimized_molecules) reactor_logger.info( "Number of products found from gamma:{} = {}".format( gamma, len(saved_inchi_strings))) reactor_logger.info( "{} geometries are considered for the next gamma cycle".format( len(orientations_to_optimize))) reactor_logger.debug("the keys of the molecules for next gamma cycle") for this_orientation in orientations_to_optimize: reactor_logger.debug("{}".format(this_orientation.name)) os.chdir(cwd) return