Message Boards Message Boards

How to classify atoms in 3-dimensional space into molecules?

Posted 4 years ago

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ļ¼š

Black is Carbon, White is Hydrogen, Red is Oxygen

I want to classify the atoms into molecules by calculating the coordinate, the goal is like this: classify atoms into molecules

How to achieve it in Mathematica?

POSTED BY: Haobo Xia
3 Replies

POSTED BY: Jason Biggs
Posted 4 years ago

Thank you very much!

POSTED BY: Haobo Xia
Posted 4 years ago

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"]]
POSTED BY: Haobo Xia
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract