6
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ 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}]? $\endgroup$
    – Domen
    Nov 23, 2022 at 16:57

1 Answer 1

6
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ 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 $\endgroup$ Nov 25, 2022 at 15:01
  • $\begingroup$ There seems to be an issue with FindGeometricTransformation - I will try to find a replacement for that and get back to you $\endgroup$
    – Jason B.
    Nov 25, 2022 at 16:09
  • $\begingroup$ @ФилиппЦветков - 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. $\endgroup$
    – Jason B.
    Dec 3, 2022 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.