Giter Club home page Giter Club logo

latticeplane's Introduction

LatticePlane

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

For the paper, please refer to https://doi.org/10.1107/S1600576722001492.

Dependencies

Installation

The following instructions are adapted from https://mathematica.stackexchange.com/a/672/61736.

  1. Open LatticePlane.m in Mathematica
  2. Choose File --> Install...
  3. Choose Type --> Package, Source --> (the open notebook), Install Name --> LatticePlane
  4. Load the package by evaluating (including the <<):
<<LatticePlane`

Ensure the name is not mispelled (including capitalization).

The Install... menu item will put the package into FileNameJoin[{$UserBaseDirectory, "Applications"}] which on Windows is %AppData%\Mathematica\Applications.

To test that it has installed correctly, open the documentation via:

?LatticePlane

Usage

Loading CIF Files

CIF files are loaded using a slightly modified version of MaXrd ImportCrystalData[] named ImportCrystalData2[]. The first argument to ImportCrystalData2 is the path to the CIF file (without the .cif extension), and the second argument is a key that will be used to access data relating to the compound.

Computing Densities

The primary functionality of LatticePlane is contained in DensityHKL[], which can be used as follows:

{Aoutn, AoutCt, hkl, Afulln, AfullCt, hklFull, elem}=DensityHKL[mpid,n,hklMax,radiusFactorIn];

where mpid is the Materials Project ID or other key for a CIF file assigned via ImportCrystalData2, n is the supercell size, hklMax is the maximum HKL index to consider, and radiusFactorIn is the maximum distance between the HKL plane of interest and each atom in the compound that is allowed for an atom to be considered in the intersection scheme. Aoutn contains the area of each element in a particular plane normalized by the radius of that atom for the unique HKL planes. AoutCt contains the total number of atoms (fractional values OK) of an element within a plane for the unique HKL planes. hkl is a list of the unique HKL planes. Afulln, AfullCt, and hklFull consider the degenerate HKL planes as well. Finally, elem is the list of unique elements.

Plotting

To reproduce the plots from the paper such as the following (annotations added manually), see PlotSymmetrizedFullHKL[] which uses several of the outputs from DensityHKl[]. fe3c-ex

Examples

Please refer to LatticePlane-example.nb. A high-throughput calculation workflow and machine learning application is given in ml-test.nb.

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.