def main(): args = parse_args() print("args", args) if args.implementation == TORCHANI: from torchani_calculator import torchani_calculator calculator = torchani_calculator(args.network_type) elif args.implementation == AES_ANI: from ani_ase import ani_ase_calculator calculator = ani_ase_calculator(args.network_type) elif args.implementation == KHAN: from khan_calculator import khan_calculator calculator = khan_calculator(args.network_type, args.khan_network, args.numb_networks) assert args.cif_file.endswith('.cif') atoms = ase_io.read(args.cif_file) print("Space group of crystal: %s" % spacegroup.get_spacegroup(atoms)) print("initial unit cell") print(atoms.cell) atom_index_group1 = [] for i in range(1, atoms.get_number_of_atoms()): if atom_belong_to_mol1(i, atoms): atom_index_group1.append(i) MC_steps = int(args.MC) all_frames = 'all_frames.xyz' for i in range(0, int(MC_steps)): atoms.set_calculator(calculator) old_frame = atoms.copy() old_frame.set_calculator(calculator) new_frame, message = Monte_Carlo(old_frame, atom_index_group1, calculator) print("MC step %d" % i) if message == 'Accepted': outfile = "Accepted_%d.cif" % i ase_io.write(all_frames, atoms, append=True) ase_io.write(outfile, atoms) atoms = new_frame.copy()
def main(): args = parse_args() print("args", args) if args.implementation == TORCHANI: from torchani_calculator import torchani_calculator calculator = torchani_calculator(args.network_type) elif args.implementation == AES_ANI: from ani_ase import ani_ase_calculator calculator = ani_ase_calculator(args.network_type) elif args.implementation == KHAN: from khan_calculator import khan_calculator calculator = khan_calculator(args.network_type, args.khan_network, args.numb_networks) assert args.cif_file.endswith('.cif') print('debug? ', args.debug) atoms = ase_io.read(args.cif_file) numb_molecules = len(molecule_lists(atoms)) print('number of molecules: ', numb_molecules) MC_stpes = args.MC space_group = Spacegroup(args.space_group) # step size in MC f1, f2, f3, f4, f5, f6, f7, f8 = args.MC_f1_f2_f3_f4_f5_f6_f7_f8 perturbation_type = args.perturbation_type molecule1_in_cell = [] for i in range(1, atoms.get_number_of_atoms()): if atom_belong_to_mol1(i, atoms): molecule1_in_cell.append(i) print("initial unit cell") print(atoms.cell) print("To do Monte Carlo for %d step." % MC_stpes) print("Molecule index in ASU are: ", molecule1_in_cell) translation_stats = [] rotation_stats = [] cell_length_a_stats = [] cell_length_b_stats = [] cell_length_c_stats = [] cell_angle_alpha_stats = [] cell_angle_beta_stats = [] cell_angle_gamma_stats = [] counter = 0 atoms_input = atoms.copy() while (counter <= MC_stpes): if isinstance(perturbation_type, list): # random_number = random.choice([1,2,3,4,5,6,7,8]) random_choices = get_random_choices( [f1, f2, f3, f4, f5, f6, f7, f8]) random_number = random.choice(random_choices) else: random_number = perturbation_dict[perturbation_type] if random_number == 1: # translation atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f1, 'translate', counter, molecule1_in_cell, MC_stpes, args.debug) translation_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() elif random_number == 2: # rotation atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f2, 'rotation', counter, molecule1_in_cell, MC_stpes, args.debug) rotation_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() elif random_number == 3: # cell_length a atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f3, 'cell_length_a', counter, molecule1_in_cell, MC_stpes, args.debug) cell_length_a_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() elif random_number == 4: # cell_length b atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f4, 'cell_length_b', counter, molecule1_in_cell, MC_stpes, args.debug) cell_length_b_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() elif random_number == 5: # cell_length c atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f5, 'cell_length_c', counter, molecule1_in_cell, MC_stpes, args.debug) cell_length_c_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() elif random_number == 6: # cell_angle alpha atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f6, 'cell_angle_alpha', counter, molecule1_in_cell, MC_stpes, args.debug) cell_angle_alpha_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() elif random_number == 7: # cell_angle beta atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f7, 'cell_angle_beta', counter, molecule1_in_cell, MC_stpes, args.debug) cell_angle_beta_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() elif random_number == 8: # cell_angle gamma atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f8, 'cell_angle_gamma', counter, molecule1_in_cell, MC_stpes, args.debug) cell_angle_gamma_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() #if counter % 1000 == 0: # with open("MC_trace_%d.json"%counter, "w") as fh: # json.dump(MC_trace, fh, indent=4) #with open("MC_trace.json", "w") as fh: # json.dump(MC_trace, fh, indent=4) #print("MC trace are recorded in: MC_trace.json") if len(translation_stats): print("Acceptance ratio of translation move is %f" % (countX("Accepted", translation_stats) / len(translation_stats))) if len(rotation_stats): print("Acceptance ratio of rotation move is %f" % (countX("Accepted", rotation_stats) / len(rotation_stats))) if len(cell_length_a_stats): print("Acceptance ratio of cell length a move is %f" % (countX("Accepted", cell_length_a_stats) / len(cell_length_a_stats))) if len(cell_length_b_stats): print("Acceptance ratio of cell length b move is %f" % (countX("Accepted", cell_length_b_stats) / len(cell_length_b_stats))) if len(cell_length_c_stats): print("Acceptance ratio of cell length c move is %f" % (countX("Accepted", cell_length_c_stats) / len(cell_length_c_stats))) if len(cell_angle_alpha_stats): print("Acceptance ratio of cell angle alpha move is %f" % (countX("Accepted", cell_angle_alpha_stats) / len(cell_angle_alpha_stats))) if len(cell_angle_beta_stats): print("Acceptance ratio of cell angle beta move is %f" % (countX("Accepted", cell_angle_beta_stats) / len(cell_angle_beta_stats))) if len(cell_angle_gamma_stats): print("Acceptance ratio of cell angle gamma move is %f" % (countX("Accepted", cell_angle_gamma_stats) / len(cell_angle_gamma_stats)))
def main(): args = parse_args() print("args", args) if args.implementation == TORCHANI: from torchani_calculator import torchani_calculator calculator = torchani_calculator(args.network_type) elif args.implementation == AES_ANI: from ani_ase import ani_ase_calculator calculator = ani_ase_calculator(args.network_type) elif args.implementation == KHAN: from khan_calculator import khan_calculator calculator = khan_calculator(args.network_type, args.khan_network, args.numb_networks) assert args.cif_file.endswith('.cif') print('debug? ', args.debug) atoms = ase_io.read(args.cif_file) numb_molecules = len(molecule_lists(atoms)) print('number of molecules: ', numb_molecules) MC_stpes = args.MC space_group = Spacegroup(args.space_group) # step size in MC f1, f2, f3, f4, f5, f6, f7, f8 = args.MC_f1_f2_f3_f4_f5_f6_f7_f8 perturbation_type = args.perturbation_type molecule1_in_cell = [] for i in range(1, atoms.get_number_of_atoms()): if atom_belong_to_mol1(i, atoms): molecule1_in_cell.append(i) print("initial unit cell") print(atoms.cell) print("To do Monte Carlo for %d step." % MC_stpes) print("Molecule index in ASU are: ", molecule1_in_cell) counter = 0 atoms.set_calculator(calculator) while (counter <= MC_stpes): if isinstance(perturbation_type, list): # random_number = random.choice([1,2,3,4,5,6,7,8]) random_choices = get_random_choices( [f1, f2, f3, f4, f5, f6, f7, f8]) random_number = random.choice(random_choices) else: random_number = perturbation_dict[perturbation_type] if random_number == 1: # translation Monte_Carlo(atoms, calculator, space_group, f1, 'translate', counter, numb_molecules, molecule1_in_cell, MC_stpes, args.debug) counter += 1 elif random_number == 2: # rotation Monte_Carlo(atoms, calculator, space_group, f2, 'rotation', counter, numb_molecules, molecule1_in_cell, MC_stpes, args.debug) counter += 1 elif random_number == 3: # cell_length a Monte_Carlo(atoms, calculator, space_group, f3, 'cell_length_a', counter, numb_molecules, molecule1_in_cell, MC_stpes, args.debug) counter += 1 elif random_number == 4: # cell_length b Monte_Carlo(atoms, calculator, space_group, f4, 'cell_length_b', counter, numb_molecules, molecule1_in_cell, MC_stpes, args.debug) counter += 1 elif random_number == 5: # cell_length c Monte_Carlo(atoms, calculator, space_group, f5, 'cell_length_c', counter, numb_molecules, molecule1_in_cell, MC_stpes, args.debug) counter += 1 elif random_number == 6: # cell_angle alpha Monte_Carlo(atoms, calculator, space_group, f6, 'cell_angle_alpha', counter, numb_molecules, molecule1_in_cell, MC_stpes, args.debug) counter += 1 elif random_number == 7: # cell_angle beta Monte_Carlo(atoms, calculator, space_group, f7, 'cell_angle_beta', counter, numb_molecules, molecule1_in_cell, MC_stpes, args.debug) counter += 1 elif random_number == 8: # cell_angle gamma Monte_Carlo(atoms, calculator, space_group, f8, 'cell_angle_gamma', counter, numb_molecules, molecule1_in_cell, MC_stpes, args.debug) counter += 1
def main(): args = parse_args() print("args", args) if args.implementation == TORCHANI: from torchani_calculator import torchani_calculator calculator = torchani_calculator(args.network_type) elif args.implementation == AES_ANI: from ani_ase import ani_ase_calculator calculator = ani_ase_calculator(args.network_type) elif args.implementation == KHAN: from khan_calculator import khan_calculator calculator = khan_calculator(args.network_type, args.khan_network, args.numb_networks) assert args.cif_file.endswith('.cif') print('debug? ', args.debug) atoms = ase_io.read(args.cif_file) numb_molecules = len(molecule_lists(atoms)) print('number of molecules: ', numb_molecules) total_number_of_molecules = numb_molecules MC_stpes = args.MC space_group = Spacegroup(args.space_group) # step size in MC f1, f2, f3, f4 = args.MC_f1_f2_f3_f4 perturbation_type = args.perturbation_type molecule1_in_cell = [] for i in range(1, atoms.get_number_of_atoms()): if atom_belong_to_mol1(i, atoms): molecule1_in_cell.append(i) # print("Space group of crystal: %s" % spacegroup.get_spacegroup(atoms)) print("initial unit cell") print(atoms.cell) print("To do Monte Carlo for %d step." % MC_stpes) print("Molecule index in ASU are: ", molecule1_in_cell) translation_stats = [] rotation_stats = [] cell_length_stats = [] cell_angle_stats = [] counter = 0 atoms_input = atoms.copy() # space_group = spacegroup.get_spacegroup(atoms) while (counter <= MC_stpes): if isinstance(perturbation_type, list): random_number = random.choice([1, 2, 3, 4]) else: random_number = perturbation_dict[perturbation_type] if random_number == 1: # translation atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f1, 'translate', counter, molecule1_in_cell, MC_stpes, args.debug) translation_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() elif random_number == 2: # rotation atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f2, 'rotation', counter, molecule1_in_cell, MC_stpes, args.debug) rotation_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() elif random_number == 3: # cell_length atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f3, 'cell_length', counter, molecule1_in_cell, MC_stpes, args.debug) cell_length_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() else: # cell_angle atoms_input.set_calculator(calculator) ret_atoms, message = Monte_Carlo(atoms_input, calculator, space_group, f4, 'cell_angle', counter, molecule1_in_cell, MC_stpes, args.debug) cell_angle_stats.append(message) counter += 1 atoms_input = ret_atoms.copy() with open("MC_trace.json", "w") as fh: json.dump(MC_trace, fh, indent=4) print("MC trace are recorded in: MC_trace.json") print("Acceptance ratio of translation move is %f" % (countX("Accepted", translation_stats) / len(translation_stats))) print("Acceptance ratio of rotation move is %f" % (countX("Accepted", rotation_stats) / len(rotation_stats))) print("Acceptance ratio of cell length move is %f" % (countX("Accepted", cell_length_stats) / len(cell_length_stats))) print("Acceptance ratio of cell angle move is %f" % (countX("Accepted", cell_angle_stats) / len(cell_angle_stats)))