Probe Software Users Forum

Software => DTSA II => Topic started by: lukmuk on September 27, 2024, 06:43:20 AM

Title: Docstring of methods
Post by: lukmuk on September 27, 2024, 06:43:20 AM
Hello Nicholas and other DTSA users,

is there a way to show the documentation string/help for methods in DTSA?
So far I cannot find a way to print it in DTSA's Jython console...

Example:

m = material("SiO2")
help(m.addElementByStoiciometry()) # doesn't work
help(addElementByStoiciometry()) # doesn't work
help(addElementByStoiciometry) # doesn't work
dir(addElementByStoiciometry) # doesn't work also with dir
...


But I see that it expects two input args when trying to call the method:
m.addElementByStoiciometry() # error: requires 2 input args


Currently I am looking at the Github source code to find the explanation: https://github.com/usnistgov/EPQ/blob/b9949d1e08ccea81907e0d7bd9d79fe7d1d4f365/src/gov/nist/microanalysis/EPQLibrary/Composition.java#L299
That works (e.g., here I see that it expects an element and a mole fraction as args), but is a bit more involved.

For "basic" functions that are not method of classes/objects, help works as expected, e.g.,
help(windowTransmission)

Maybe I am overlooking something or is it a limitation of the Jython console?

Thanks for any help!

Kind regards,
lukmuk
Title: Re: Docstring of methods
Post by: Nicholas Ritchie on September 27, 2024, 07:04:16 AM
There is a little bit of a mismatch between Jython and Java.  As you note,

> help(material)
material("TiO2",[density=4.27])
The function creates a Composition object by first checking the material database for a material with the specified name. If the material isn't in the database it will then attempt to parse the name as a chemical formula.  If both of these fail the method will return None.

works.   This is because I explicitly added help for functions implemented in Jython but Jython doesn't know how to look up the documentation for code developed in Java.  So,

4> help(m.addElementByStoiciometry)
Java Method:
No arguments: addElementByStoiciometry()

is worse than non-helpful. It is incorrect.  As you note, m.addElementByStoiciometry(...) takes two arguments - an Element and an integer.  So

4> m = material("SiO2")
5> m.addElementByStoiciometry(element("Fe"),1)
6> describe(m)
SiO2
Density 3 g/cm³
Element Z Mass Frac Norm Mass Atom Frac
Oxygen 8 0.140578 0.140578 0.333334
Silicon 14 0.123386 0.123386 0.166666
Iron 26 0.736036 0.736036 0.5
-- 21.989 1 1.0 1.0

You could also use epq.Element.Fe as an optimized version of element("Fe")

The best best is, as you discovered, to look up the source code for the EPQ library on Github. In this case,  https://github.com/usnistgov/EPQ/blob/master/src/gov/nist/microanalysis/EPQLibrary/Material.java (https://github.com/usnistgov/EPQ/blob/master/src/gov/nist/microanalysis/EPQLibrary/Material.java)
Title: Re: Docstring of methods
Post by: lukmuk on September 27, 2024, 07:29:54 AM
Hello Nicholas,

thanks for the quick reply and clarifications.
All makes sense now (Java and Python mixture) and using Github as documentation works well!

Kind regards,
lukmuk