Package: scinumtools
scinumtoolsPython packagescinumtoolscontains essential tools for scientific and numerical calculations, simulation setup and data analysis.DocumentationFor more information, see the scinumtoolsdocumentation.
The documentation is currently in a process of writing, so any comments and suggestions for improvement are heartily welcomed.Quick startThe newest release ofscinumtoolsis available onPyPiand can be easily installed usingpippackage manager:pip3installscinumtoolsBesides several useful tools, packagescinumtoolsconsist of four main submodules: expression solver, physical units, material properties and DIP.Expression SolverUsingexpression solverone can quickly build a custom parser that can process numerical, logical and textual expressions. This module is an integral part of other submodules.
For more description and examples ofExpression Solverplease refer to the documentation.>>>fromscinumtools.solverimport*>>>classAtomCustom(AtomBase):>>>value:str>>>def__init__(self,value:str):>>>self.value=str(value)>>>def__add__(self,other):>>>returnAtomCustom(self.value+other.value)>>>def__gt__(self,other):>>>returnAtomCustom(len(self.value)>len(other.value))>>>operators={'add':OperatorAdd,'gt':OperatorGt,'par':OperatorPar}>>>steps=[>>>dict(operators=['par'],otype=Otype.ARGS),>>>dict(operators=['add'],otype=Otype.BINARY),>>>dict(operators=['gt'],otype=Otype.BINARY),>>>]>>>withExpressionSolver(AtomCustom,operators,steps)ases:>>>es.solve("(limit + 100 km/s) > (limit + 50000000000 km/s)")'False'Physical UnitsThis submodule has an aim to make calculations withphysical unitsquick and easy. It includes multiple types of units, constants and implements standard numerical operations with physical quantities. Besides that, it features unit convertor, supports calculations with uncertainties and can be used in combination with third party libraries like NumPy, or Decimal.
For more description and examples ofPhysical Unitsplease refer to the documentation.>>>importnumpyasnp>>>fromscinumtools.unitsimportQuantity,Unit>>>Quantity(23.34,'kg*m2/s2').to('erg')# unit conversionsQuantity(2.334e+08erg)>>>u=Unit()# calculations with units>>>34*u.cm+53*u.dmQuantity(5.640e+02cm)>>>Quantity(23.34,'cm',abse=0.03)# uncertainitiesQuantity(2.3340(30)e+01cm)>>>Quantity(3,'A').value('dBA')# logarithmic units9.542425094393248>>>np.sqrt(Quantity([23,59,20,10],'m2'))# arrays and NumPyQuantity([4.7967.6814.4723.162]m)Material PropertiesSimulation setups often require atomic and molecular properties of various materials. The core of this submodule, molecular expression solver, is designed to simplify calculations of such properties from a given molecular formula.
For more description and examples ofMaterial Propertiesplease refer to the documentation.>>>fromscinumtools.unitsimportQuantity>>>fromscinumtools.materialsimportMolecule>>>withMolecule('H2O',natural=False)asc:>>>c.set_amount(rho=Quantity(997,'kg/m3'),V=Quantity(1,'l'))>>>c.print()Properties:Massdensity:Quantity(9.970e+02kg*m-3)Molecularmass:Quantity(1.801e+01Da)Moleculardensity:Quantity(3.334e+28m-3)Volume:Quantity(1.000e+00l)Elements:expressionelementisotopeionisationA[Da]ZNeHH101.007825101OO16015.994915888Molecule:expressioncountA[Da]ZNex[%]X[%]n[cm-3]rho[g/cm3]n_VM_V[g]H2.02.0156502.0000000.0000002.00000066.66666711.1914876.667280e+220.1115796.667280e+25111.579129O1.015.9949158.0000008.0000008.00000033.33333388.8085133.333640e+220.8854213.333640e+25885.420871avg1.56.0035223.3333332.6666673.33333333.33333333.3333333.333640e+220.3323333.333640e+25332.333333sum3.018.01056510.0000008.00000010.000000100.000000100.0000001.000092e+230.9970001.000092e+26997.000000Dimensional Input ParametersDIPis a serialization language that was designed to collect, manage, convert, document and validate dimensional input parameters used by numerical codes. The main goal of this package is to help developers to focus less on initialization processes mentioned above and more on actual code development.DIPshould serve as a quick tool that makes user interface with the code clear and straightforward.
For more description and examples ofDIPplease refer to the documentation.>>>fromscinumtools.dipimportDIP,Format>>>withDIP()asdip:>>>dip.add_source("settings",'settings.dip')>>>dip.add_unit("length",1,"m")>>>dip.from_string(""">>>     box>>>       width float = 23 [length]>>>       height float = 11.5 cm>>>     sphere>>>       radius float = {settings?sphere.radius}>>>     """)>>>env=dip.parse()>>>env.data(Format.TUPLE){'box.width':(23.0,'[length]'),'box.height':(11.5,'cm'),'sphere.radius':(34.2,'mm')}Alternative Python modulediplimplements basic loading and dumping functionality of DIP and provides quick solution for data parsing using DIP.>>>importdipl>>>>>>dipl.load(""">>> width float = 173.34 cm>>> age int = 24 yr>>> """){'width':(173.34,'cm'),'age':(24,'yr')}>>>>>>dipl.dump({>>>'children':['John','Jenny','Jonah'],>>>'car':True>>>})childrenstr[3]=["John","Jenny","Jonah"]carbool=true