def __init__(self, mol=None, symmetrize=True, tm=Tol_matrix(prototype="molecular")): mo = None self.smile = None self.torsionlist = None if type(mol) == str: # Parse molecules: either file or molecule name tmp = mol.split(".") self.name = tmp[0] if len(tmp) > 1: # Load the molecule from the given file if tmp[-1] in ["xyz", "gjf", "g03", "json"]: if os.path.exists(mol): mo = Molecule.from_file(mol) else: raise NameError("{:s} is not a valid path".format(mol)) elif tmp[-1] == 'smi': self.smile = tmp[0] symbols, xyz, self.torsionlist = self.rdkit_mol_init(tmp[0]) mo = Molecule(symbols, xyz) symmetrize = False else: raise NameError("{:s} is not a supported format".format(tmp[-1])) else: # print('\nLoad the molecule {:s} from collections'.format(mol)) mo = molecule_collection[mol] elif hasattr(mol, "sites"): # pymatgen molecule self.name = str(mol.formula) mo = mol if mo is None: msg = "Could not create molecules from given input: {:s}".format(mol) raise NameError(msg) self.props = mo.site_properties if len(mo) > 1: if symmetrize: pga = PointGroupAnalyzer(mo) mo = pga.symmetrize_molecule()["sym_mol"] mo = self.add_site_props(mo) self.mol = mo self.tm = tm self.get_box() self.volume = self.box.volume self.get_radius() self.get_symbols() self.get_tols_matrix() xyz = self.mol.cart_coords self.reset_positions(xyz-self.get_center(xyz))
#Testing water mol = deepcopy(c60) print("Original molecule:") print(mol) print() #Apply random rotation to avoid lucky results R = aa2matrix(1, 1, random=True) R_op = SymmOp.from_rotation_and_translation(R, [0, 0, 0]) mol.apply_operation(R_op) print("Rotated molecule:") print(mol) print("============================================") pga = PointGroupAnalyzer(mol) mol = pga.symmetrize_molecule()['sym_mol'] #orientation_in_wyckoff_position(mol, sg, WP's index in sg) #returns a list of orientations consistent with the WP's symmetry. #We can choose any of these orientations at random using np.random.choice #To use an orientation, do mol.apply_operation(orientation) #Spacegroup WP 24l (index 2) in sg 221 has m.. symmetry allowed = orientation_in_wyckoff_position(mol, 221, 2, randomize=True) print("Found " + str(len(allowed)) + " orientations:") print("------------------------------") for op in allowed: mo = deepcopy(mol) mo.apply_operation(op) print() print(mo)