xnx / pyvalem Goto Github PK
View Code? Open in Web Editor NEWA Python package for managing simple chemical species and states
License: GNU General Public License v3.0
A Python package for managing simple chemical species and states
License: GNU General Public License v3.0
e.g. n=2, l=1 not l=1, n=2 for the "2p" configuration.
NB does J = # get interpreted as a rotational quantum number when fine-structure (total electronic angular momentum for an atom or ion) is intended?
Currently, Formula('He+42')
happily executes, while the maximal charge should be 2:
In [1]: Formula('He+42').charge
Out[1]: 42
Ensure the total atomic number of Formula instance is greater or equal than the charge:
In [47]: formula = Formula('CH4+42')
...: total_atomic_number = sum(formula.atom_stoich[atom.symbol] * atom.Z for atom in formula.atoms)
...: if total_atomic_number < formula.charge:
...: raise FormulaParseError(f'Charge {formula.charge} if greater than the total atomic number {total_atomic_number}!')
...:
...:
---------------------------------------------------------------------------
FormulaParseError Traceback (most recent call last)
<ipython-input-47-b8fa6fbad41d> in <module>
2 total_atomic_number = sum(formula.atom_stoich[str(atom)] * atom.Z for atom in formula.atoms)
3 if total_atomic_number < formula.charge:
----> 4 raise FormulaParseError(f'Charge {formula.charge} if greater than the total atomic number {total_atomic_number}!')
5
FormulaParseError: Charge 42 if greater than the total atomic number 10!
Atom
and Isotope
instances from Formula.atoms
and their atom_symbol
s from Formula.atom_stoich.keys()
is not defined by atom.symbol
, but rather appears to be built up through a series of if ... else
cases. However they appear to match.Is there a way to express solid solution using chemical formula? By solid solution, I am referring to formula describing a crystal composed of different kinds of atoms occupying equivalent sites within the crystal lattice. This is a common occurrence for natural materials, i.e. minerals. I've included a few examples below:
olivine
Commonly expressed as (Mg, Fe)2SiO4, equivalent to (Mg1−xFex)2SiO4. The first formulation is a very common method used by geochemists to denote solid solution where in this case Fe and Mg exist and can vary in nature from pure Mg to pure Fe, with any ratio of the two possible.
hornblende
This family of minerals is particularly complex, with numerous varieties existing, a product of numerous solid solution series existing:
Any thoughts as to feasibility of expressing such non-stoichiometric formulae? Thanks in advance!
I should note I borrowed heavily from wikipedia for the examples. Thanks Wikipedia editors!
Formulas like [Cu(H2O)4]SO4*H2O are usual in chemistry(see https://en.wikipedia.org/wiki/Glossary_of_chemical_formulae), but pyvalem seems to have problem with that. No formulas with nested parenthesis work for me. Is that a bug?
f = Formula('H20')#OK
f = Formula('[Cu(H2O)4]SO4*H2O') #fails
<...>
pyvalem.formula.FormulaParseError: Invalid formula syntax: [Cu(H2O)4]SO4*H2O
f = Formula('[Cu(H2O)4]SO4') #fails
<...>
pyvalem.formula.FormulaParseError: Invalid formula syntax: [Cu(H2O)4]SO4
f = Formula('(Cu(H2O)4)SO4') #fails
<...>
pyvalem.formula.FormulaParseError: Invalid formula syntax: (Cu(H2O)4)SO4
Unless I'm missing something in the underlying physics, I think states like '1v1 + 0v2 + 0v3' should be either parsed as '1v1', or raise an exception. This is what happens instead:
In [20]: StatefulSpecies('M 0v1+0v2+0v3')
Out[20]: M ν1+ν2+ν3
In [21]: StatefulSpecies('M 1v1+0v2+0v3')
Out[21]: M ν1+ν2+ν3
In [22]: StatefulSpecies('M 0v1+1v2+0v3')
Out[22]: M ν1+ν2+ν3
In [23]: StatefulSpecies('M 0v1+0v2+1v3')
Out[23]: M ν1+ν2+ν3
In [24]: StatefulSpecies('M 1v1+1v2+1v3')
Out[24]: M ν1+ν2+ν3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.