Skip to content

Some molecules fail isomorphism check #1740

@alongd

Description

@alongd

Bug Description

I'm checking isomorphism between a molecule generated from xyz. When generated in the same atom order, the isomorphism check returns True. When generated in a different atom order (changing C and Cl), the isomorphism check returns False.

How To Reproduce

Run the following script:

from rmgpy.molecule.molecule import Atom, Molecule
import numpy as np


def s_bonds_mol_from_xyz(xyz):
    mol = Molecule()
    for symbol, coord in zip(xyz['symbols'], xyz['coords']):
        atom = Atom(element=symbol)
        atom.coords = np.array([coord[0], coord[1], coord[2]], np.float64)
        mol.add_atom(atom)
    mol.connect_the_dots()
    return mol


xyz1 = {'symbols': ('Cl', 'F', 'C', 'O', 'O', 'H'),
        'isotopes': (35, 19, 12, 16, 16, 1),
        'coords': ((3.09727149, -1.18647281, -0.9370755),
                   (0.27568368, 0.01156702, -0.4122491),
                   (1.50048866, -0.50848248, -0.64006761),
                   (1.93561914, 0.7474161, -1.16759033),
                   (2.33727805, 1.9067071, -1.65453438),
                   (3.25580294, 1.83954553, -1.92546105))}
xyz2 = {'symbols': ('C', 'F', 'Cl', 'O', 'O', 'H'),  # this is xyz1 with C and Cl replaced
        'isotopes': (12, 19, 35, 16, 16, 1),
        'coords': ((1.50048866, -0.50848248, -0.64006761),
                   (0.27568368, 0.01156702, -0.4122491),
                   (3.09727149, -1.18647281, -0.9370755),
                   (1.93561914, 0.7474161, -1.16759033),
                   (2.33727805, 1.9067071, -1.65453438),
                   (3.25580294, 1.83954553, -1.92546105))}
xyz3 = {'symbols': ('C', 'F', 'Cl', 'O', 'O', 'H'),  # identical to xyz2
        'isotopes': (12, 19, 35, 16, 16, 1),
        'coords': ((1.50048866, -0.50848248, -0.64006761),
                   (0.27568368, 0.01156702, -0.4122491),
                   (3.09727149, -1.18647281, -0.9370755),
                   (1.93561914, 0.7474161, -1.16759033),
                   (2.33727805, 1.9067071, -1.65453438),
                   (3.25580294, 1.83954553, -1.92546105))}

mol1 = s_bonds_mol_from_xyz(xyz1)
mol2 = s_bonds_mol_from_xyz(xyz2)
mol3 = s_bonds_mol_from_xyz(xyz3)

print(mol2.is_isomorphic(mol1))  # gives False
print(mol2.is_isomorphic(mol3))  # gives True

print(mol1.to_adjacency_list())
print(mol2.to_adjacency_list())
print(mol3.to_adjacency_list())

Expected Behavior

If I understand correctly, the isomorphism check should not care about atom order, and should return a consistent answer, hopefully the correct one (True in this case)

Installation Information

master branches (ce53e34 for RMG-Py)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions