-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
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:

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)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels