예제 #1
0
def check_symmetry(met_filename):
    """ Function that checks if the given metabolite is symmetric.
    Uses pymatgen package for symmetry related operations, and
    RDKit for Molfile conversion to XYZ format. Requires Molfiles
    of the metabolites to be present in the working_dir/metabolites
    folder.
    Current criterion for symmetricity is for every carbon except one
    (central, if molecule consists of odd number of carbons) to have
    at least one equivalent carbon in the structure.

    Parameters
    ----------
    met_filename : str
        Filename of the specific Molfile

    Returns
    -------
    symmetrical : bool
        True if metabolite is symmetric, False if not.

    """
    symmetrical = False
    # Disable RDKit warnings
    RDLogger.DisableLog('rdApp.*')
    # Counter for non symmetrical carbon atoms
    non_eq_carbons = 0
    carbons = 0
    # Convert Molfile to XYZ string
    molecule = Chem.MolFromMolFile(f'metabolites/{met_filename}')
    molecule_xyz = Chem.rdmolfiles.MolToXYZBlock(molecule)

    # Create IMolecule object to analyze its' symmetricity
    try:
        molecule_obj = structure.IMolecule.from_str(molecule_xyz, fmt='xyz')
        if len(molecule_obj) == 1:
            return symmetrical
        # Initialize point group analyzer
        pg_analyzer = analyzer.PointGroupAnalyzer(molecule_obj)

    except (IndexError, ValueError):
        # '*' is unrecognized in particular
        print(f'{met_filename} contains unrecognized symbols')
        return symmetrical
    # Extract equal atom sets
    eq_atoms = pg_analyzer.get_equivalent_atoms()
    for i in eq_atoms['eq_sets'].keys():
        if str(molecule_obj[i].specie) == 'C':
            carbons += 1
            if len(eq_atoms['eq_sets'].get(i)) == 1:
                non_eq_carbons += 1
                if non_eq_carbons > 1:
                    return symmetrical

    # Molecule has more than 1 carbon, and at most 1 non-symmetrical carbon
    if carbons > 1:
        symmetrical = True

    return symmetrical
예제 #2
0
def get_pointgroup(atoms: ase.Atoms) -> str:
    """
    uses pymatgen.symmetry.analyzer
	"""
    atoms.center()
    symbs = atoms.get_chemical_symbols()
    pos = atoms.get_positions()
    mol = pmg.Molecule(symbs, pos)
    return pysym.PointGroupAnalyzer(mol).sch_symbol
예제 #3
0
def getPointgroup(kind, storagepath):
    if kind != 'molecule': return None
    import pymatgen
    import pymatgen.io.ase as pmgase
    import pymatgen.symmetry.analyzer as psa
    atoms = getAtoms(storagepath)
    cm = atoms.get_center_of_mass()
    m = pymatgen.Molecule(atoms.get_chemical_symbols(),
                          atoms.get_positions() - cm)
    return psa.PointGroupAnalyzer(m).sch_symbol
예제 #4
0
def getPointgroup(kind,inittraj): 
	if kind == 'molecule':
		atoms 	= pickle.loads(inittraj)
		cm 		= atoms.get_center_of_mass()
		m 		= pymatgen.Molecule(atoms.get_chemical_symbols(),atoms.get_positions()-cm)
		try:
			return psa.PointGroupAnalyzer(m).sch_symbol
		except ValueError:
			viz.view(atoms)
			sys.exit()
	else: return None
예제 #5
0
def structure_symmetry():
    if is_pbc():
        struct = readstructure(crystal=True, molecule=False)
        ast = analyzer.SpacegroupAnalyzer(struct)
        print("{} : {}".format('Structure Type', 'periodicity'))
        print("{} : {}".format('Lattice Type', ast.get_lattice_type()))
        print("{} : {}".format('Space Group ID', ast.get_space_group_number()))
        print("{} : {}".format('International Symbol',
                               ast.get_space_group_symbol()))
        print("{} : {}".format('Hall Symbol', ast.get_hall()))
        return
    else:
        struct = readstructure(crystal=False, molecule=True)
        ast = analyzer.PointGroupAnalyzer(struct)
        print("{} : {}".format('Structure Type', 'non-periodicity'))
        print("{} : {}".format('International Symbol', ast.get_pointgroup()))
        return