Coder Social home page Coder Social logo

sgbaird / latticeplane Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 2.71 MB

Calculate atomic lattice plane densities in arbitrary crystal structures (CIF input) for arbitrary lattice planes (HKL indices).

License: MIT License

Mathematica 99.98% Python 0.02%
crystallography cif hkl mathematica lattice-plane planar-density

latticeplane's People

Contributors

sgbaird avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

wangvei

latticeplane's Issues

Issues with reliably computing planar intersections

PlaneIntersection[\[ScriptCapitalP]_, \[ScriptCapitalU]_] := 
 Module[{\[ScriptCapitalP]1, \[ScriptCapitalB], \[ScriptCapitalM], \
\[ScriptCapitalP]crop, \[ScriptCapitalP]int, shapes, bmesh, d, order, 
   coords, TF},
  If[Head@\[ScriptCapitalP] === 
    InfinitePlane, \[ScriptCapitalP]1 = {\[ScriptCapitalP]}, \
\[ScriptCapitalP]1 = \[ScriptCapitalP]];
  \[ScriptCapitalB] = 
   RegionResize[BoundingRegion[\[ScriptCapitalU]], 
    Scaled@Rationalize[
      1.1(*100$MachineEpsilon*)]];(*for cropping the plane*)
  \[ScriptCapitalP]crop = 
   RegionIntersection[#, \[ScriptCapitalB]] & /@ \[ScriptCapitalP]1;
  \[ScriptCapitalP]crop = 
   CanonicalizePolygon /@ N[\[ScriptCapitalP]crop];
  \[ScriptCapitalP]int = 
   RegionIntersection[#, N@\[ScriptCapitalU]] & /@ 
    N[\[ScriptCapitalP]crop];
  shapes = OpenCascadeShape[#] & /@ \[ScriptCapitalP]int;
  bmesh = OpenCascadeShapeSurfaceMeshToBoundaryMesh[#] & /@ shapes;
  coords = #["Coordinates"] & /@ bmesh;
  TF = CoplanarPoints /@ coords;
  coords = 
   MapThread[
    If[#1, #2, 
      DimensionReduction[#2, 2][#2, "ReconstructedData"]] &, {TF, 
     coords}];
  {d, order} = (FindShortestTour[#] & /@ coords)\[Transpose];
  \[ScriptCapitalP]int = 
   MapThread[Polygon[#1[[#2[[;; -2]]]]] &, {coords, order}]
  ]

image

Without CanonicalizePolygon (which is how it was before I tried resolving a bug #1):

Message[CoplanarPoints::pts, $Failed["Coordinates"]] "\!\($Failed[\"Coordinates\"]\) should be a non-empty list of points."

Upon further inspection, this was due to the intersection being incorrectly determined as a line instead of a plane AFAIK. Adding CanonicalizePolygon seemed to resolve this issue for mp-134 (Al), but now the results for mp-510623 (Fe3C) are off (maybe they're off for mp-134 since I didn't do manual verification of the values). The PlotSymmetrizedFullHKL function isn't even working because all of the intersection areas were determined to be zero for Fe.

This is running on Mathematica 13.0.1.0 on Microsoft Windows 64-bit.
image

Getting the plane intersection functions to be robust across a variety of use-cases has been very difficult, and if I'm not mistaken, somewhere between 12.2 and 13.0 there's a bug that has been introduced. Haven't verified by reverting to 12.2.

The issue might also be with how the intersections between the bounded plane and the atom hard spheres are being computed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.