Hi Eric Rimbey,
Thank you for your reply and comments.
Some of these functions are listable, or designed to work with a list
as input. In addition to cleaning up the last step, I'd try to make it
more readable with better variable names.
I made the following modifications and adjustments according to your suggestions:
In[17]:= Clear["Global`*"];
translation={1/2,1/2,1/2};
wyckoffposition={{0,0,z+1/8},{0,1/2,z+3/8},{1/2,0,-z+5/8},{1/2,1/2,-z+3/8}};
Your Solve is trivial, but I'm assuming that the real problem might
have some complexity, or that you might want to solve with different
equations.
What you said is absolutely right. In fact, here to deal with the general problem is as follows:
Give a point by its relative coordinates, in fractions, decimals, or variable parameters {a * x, b * y, c * z}, where the coefficients a, b, c are real numbers, then perform the following steps: First, take out the fractional part of the coordinate component, and then match the results to the corresponding coordinate representation in the following table:
In my example, the point, a.k.a., the atom position is (0, 0, 0.0729). In this simple case, we can see the matched pattern should be {0,0,z + 1/8} as shown in the above table, so the corresponding general solution should be something as follows:
In[62]:= OffsetRule = Flatten[Solve[{0,0,z + 1/8} == FractionalPart[{0,0,0.0729}], z]]
Out[62]= {z -> -0.0521}
However, I still haven't figured out how to solve this problem about any general expression given in the form {a * x, b * y, c * z}, where the coefficients a, b, c are real numbers.
So, we might want to isolate that a bit rather than have it buried.
Also, doing ReplaceAll with rules nested in lists produces a nested
result, so you can simplify your flattening process if you don't
introduce nested lists in the first place.
The corresponding code snippet using the new variable names:
With[
{coordinateRule = Flatten[Solve[{0,0,z + 1/8} == FractionalPart[{0,0,0.0729}], z]]},
Flatten[
FractionalPart[{wyckoffposition, TranslationTransform[translation][wyckoffposition]} /. coordinateRule],
1]]
Alternatively (use Catenate instead of Flatten):
With[
{coordinateRule = Flatten[Solve[{0,0,z + 1/8} == FractionalPart[{0,0,0.0729}], z]]},
Catenate[FractionalPart[{wyckoffposition, TranslationTransform[translation][wyckoffposition]} /. coordinateRule]]]
Best,
Zhao