xiahaobo
(Haobo Xia)
May 20, 2020, 5:22pm
1
I want to solve a problem: There are some atoms in 3-dimensional space, those atoms belong to some molecules, we know the kind and coordinate of the atoms, but we don’ t know which atom belong to which kind of molecule, we need to classify the atoms. How to deal with it in Mathematica?
For example, I have a alcohol-water blend, but I only know the kind and coordinate of the atoms, as shown in the figure:
I want to classify the atoms into molecules by calculating the coordinate, the goal is like this:
How to achieve it in Mathematica?
xiahaobo
(Haobo Xia)
May 20, 2020, 5:34pm
2
The figures shown above are generated by these codes:
RandomTransform[n_, range_: 10] :=
Table[{RotationTransform[RandomReal[2 Pi], RandomReal[1, 3]],
RandomReal[range, 3]}, n]
ColorTrans[atomlist_,
r_] := {Switch[#[[1]], "C", Black, "H", White, "O", Red],
Sphere[#[[2]], r]} & /@ Flatten[atomlist, 1]
ListOfAtoms[translist_, name_] :=
Thread[{AtomList[Molecule[name]][[All, 1]],
Function[{rt, tr},
tr + # & /@ (rt /@
QuantityMagnitude[
Molecule[name]["AtomCoordinates"]])][#[[1]], #[[2]]]}] & /@
translist
AtomsPlot[translist_, name_, r_] :=
Graphics3D[ColorTrans[ListOfAtoms[translist, name], r]]
ListOfMolecules[translist_, name_] :=
Molecule[name,
AtomCoordinates ->
Function[{rt, tr},
tr + # & /@ (rt /@
QuantityMagnitude[
Molecule[name]["AtomCoordinates"]])][#[[1]], #[[2]]]] & /@
translist
MoleculesPlot[translist_, name_] :=
Show @@ MoleculePlot3D /@ ListOfMolecules[translist, name]
trans1 = RandomTransform[10];
trans2 = RandomTransform[10];
Show[AtomsPlot[trans1, "water", 0.2],
AtomsPlot[trans2, "ethanol", 0.2]]
Show[MoleculesPlot[trans1, "water"], MoleculesPlot[trans2, "ethanol"]]