Skip to content

$CrystalData warning when wrapping MaXrd into another package, then evaluating on Wolfram Client Library for Python #5

@sgbaird

Description

@sgbaird

There seems to be some issue with using the Global variable $CrystalData (I realize this is kind of a nested problem - wrapped in package then called in a Wolfram client without a Front End). Here's a MWE:

BeginPackage["DependencyTest`", "MaXrd`"];
context = Evaluate[Context[] <> "*"];
privateContext = Evaluate[Context[] <> "Private`*"];
Unprotect @@ Names[context];
Unprotect[context];
ClearAll @@ Names[context];
ClearAll[privateContext];

AccessCrystalData::usage = "wrap around $CrystalData"

Begin["`Private`"];
AccessCrystalData[mpid_, n_] := Module[{crystalData},
ImportCrystalData[mpid<>".cif",mpid,"OverwriteWarning"->False];
ExpandCrystal[mpid,{n,n,n},"NewLabel"->mpid<>"_2","StoreTemporarily"->False];
crystalData = $CrystalData[[mpid<>"_2"]]
]

End[];
Protect@@Names[context];
Protect[context];
EndPackage[];

When called using Wolfram Client Library for Python:

from wolframclient.evaluation import WolframLanguageSession
from wolframclient.language import wl, wlexpr
with WolframLanguageSession() as s:
    s.evaluate(wl.Get('DependencyTest`'))
    s.evaluate(wl.SetDirectory('C:/Users/sterg/Documents/')) # assumes that 'mp-134.cif' is in Documents folder
    crystalData = s.evaluate(wl.DependencyTest.AccessCrystalData('mp-134', 1))
    print(crystalData)

I get the following warning ⚠️

The symbol $CrystalData at position 1 should have an immediate value defined.

However, the output seems to be OK, except for the space group which seems to just output some unicode characters in place of 3-bar:
image

Doesn't seem to affect me a ton, but kind of strange.

Upon further inspection, taking it out of the wrapper package also gives the warning:

with WolframLanguageSession() as s:
    s.evaluate(wl.Get('MaXrd`'))
    s.evaluate(wl.SetDirectory('C:/Users/sterg/Documents/')) # assumes that 'mp-134.cif' is in Documents folder
    mpid = 'mp-134'
    n = 1
    s.evaluate(wl.MaXrd.ImportCrystalData(mpid+'.cif',mpid,OverwriteWarning=False))
    s.evaluate(wl.MaXrd.ExpandCrystal(mpid,[n,n,n],NewLabel=mpid+'_2',StoreTemporarily=False))
    crystalData = s.evaluate(
        wlexpr(
            '''
            $CrystalData[["mp-134_2"]]
            '''
        )
    )
    print(crystalData)

mp-134 cif file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions