Stianpr20 / MaXrd

Symmetry data and utilities related to crystallography and X-ray scattering
MIT License
25 stars 3 forks source link

How to extract atomic positions from CrystalPlot? #4

Closed sgbaird closed 3 years ago

sgbaird commented 3 years ago

The way I'm doing it right now (with the correlated atoms) is:

\[ScriptCapitalC] = 
 CrystalPlot["GalliumArsenide", StructureSize -> {1, 1, 1}]
\[ScriptCapitalP] = {#} & /@ 
   Cases[\[ScriptCapitalC], _Sphere, \[Infinity]][[;; , 1]];

Displayed as:

TableForm[\[ScriptCapitalP]\[Transpose], 
 TableHeadings -> {None, GetElements["GalliumArsenide"]}]

Not sure if there's an easier built-in way.

Stianpr20 commented 3 years ago

When the option "StructureSize" is used in CrystalPlot, the structure is only stored temporarily. In this case, I suggest “making” the crystal first, then extract the coordinates.

Making the crystal:

ExpandCrystal["GalliumArsenide", "NewLabel" -> "GaAs"](* Defaults to 1x1x1 *)

Plot it if you like with CrystalPlot["GaAs"]. Extract the columns with chemical element and coordinates:

$CrystalData[["GaAs", "AtomData", All, {"Element", "FractionalCoordinates"}]]

Also, you can export the atomic position of a structure in a "DISCUS" format like this:

ExportCrystalData["DISCUS", "GaAs", "~/Desktop/GaAs.txt"]
sgbaird commented 3 years ago

Extract the columns with chemical element and coordinates:

$CrystalData[["GaAs", "AtomData", All, {"Element", "FractionalCoordinates"}]]

Also, you can export the atomic position of a structure in a "DISCUS" format like this:

ExportCrystalData["DISCUS", "GaAs", "~/Desktop/GaAs.txt"]

This only seems to work as intended if alpha == beta == gamma == 90 degrees Otherwise the coordinates need to be transformed via the correct basis vectors.

For example,

R = GetCrystalMetric["GalliumArsenide", ToCartesian -> True];
coords = coords . R\[Transpose];
Stianpr20 commented 3 years ago

Yes, crystallographic coordinates are used by default, but CrystalPlot objects contain Cartesian coordinates.

In the latest commit, I've added the function GetAtomCoordinates which can extract coordinates of crystal (labels) and CrystalPlot objects. It has a Boolean option "Cartesian" for toggling the output coordinate system.