6

Why the plot of the molecules with similar structures is not in the same orientation?

Row@{MoleculePlot@Molecule@"N1(c2c(Sc3c1cccc3)cccc2)CCCN(C)C",MoleculePlot@Molecule@"C\\1(/c2c(Sc3c1cccc3)ccc(c2)Cl)=C\\CCN(C)C"}

enter image description here

Is it possible to force MoleculePlot to show them in the same orientation?

  • Are you looking for some automatic way of aligning the two molecules, and then plotting them in the same orientation? Or are you satisfied with manual Row[{Rotate[MoleculePlot@mol1, -Pi/2], MoleculePlot@mol2}]? – Domen Nov 23 '22 at 16:57

1 Answers1

6

I would use something like this

moleculeAlign2D[m1_, m2_] := Catch @ Module[
    {mol1, mol2, mcs, aligned},
    mol1 = If[MemberQ[Options @ m1, HoldPattern[AtomDiagramCoordinates -> _List]],
        m1,
        MoleculeModify[m1, "ComputeAtomDiagramCoordinates"]
    ];
    mol1 = Molecule[mol1,
        AtomDiagramCoordinates -> Automatic,
        AtomCoordinates -> MapApply[{#, #2, 0.}&,
            mol1["AtomDiagramCoordinates", IncludeHydrogens -> "ExplicitOnly"]
        ]
    ];
    mol2 = Molecule[mol2 = MoleculeModify[m2, "ComputeAtomDiagramCoordinates"],
        AtomDiagramCoordinates -> Automatic,
        AtomCoordinates -> MapApply[{#, #2, 0.}&,
            mol2["AtomDiagramCoordinates", IncludeHydrogens -> "ExplicitOnly"]
        ]
    ];
    mcs = MoleculeMaximumCommonSubstructure @ {mol1, mol2};
    aligned = MoleculeAlign[mol1, mol2, mcs];
    If[!MoleculeQ[aligned], Throw[$Failed]];
    Molecule[mol2,
        AtomCoordinates -> Automatic,
        AtomDiagramCoordinates -> Part[
            aligned["AtomCoordinates",
                TargetUnits -> None, IncludeHydrogens -> "ExplicitOnly"
            ],
            All, 1;;2
        ]
    ]
]

To test

m1 = Molecule@"N1(c2c(Sc3c1cccc3)cccc2)CCCN(C)C";
m2 = Molecule@"C\\1(/c2c(Sc3c1cccc3)ccc(c2)Cl)=C\\CCN(C)C";
m2b = moleculeAlign2D[m1, m2];

GraphicsRow[MoleculePlot /@ {m1, m2b}]

enter image description here

Jason B.
  • 68,381
  • 3
  • 139
  • 286
  • It works not always well... For example if we take m1 = Molecule@"S(c1cc2N(c3c(Sc2cc1)cccc3)CCCN1CCN(CC1)C)(N(C)C)(=O)=O"; m2 = Molecule@"N1(c2c(Sc3c1cccc3)ccc(C(F)(F)F)c2)CCCN1CCN(CC1)CCO"; the molecule will be not rotated but distorted – Филипп Цветков Nov 25 '22 at 15:01
  • There seems to be an issue with FindGeometricTransformation - I will try to find a replacement for that and get back to you – Jason B. Nov 25 '22 at 16:09
  • @ФилиппЦветков - I hope the new version of the function is more robust. It uses the MoleculeAlign function by just appending a zero z-coordinate to the 2D coordinates. – Jason B. Dec 03 '22 at 23:42