Code Monkey home page Code Monkey logo

pyvalem's People

Contributors

hanicinecm avatar xnx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

paulsaxe jpcurada

pyvalem's Issues

formula.Formula does not validate maximal charge against total atomic number.

Problem:

Currently, Formula('He+42') happily executes, while the maximal charge should be 2:

In [1]: Formula('He+42').charge
Out[1]: 42

Suggested solution:

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!

Problems with the suggested solution:

  • Some formulas do not define charge
  • The mapping between the Atom and Isotope instances from Formula.atoms and their atom_symbols 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.

support for expressing solid solution in formula definitions

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:

  • Magnesiohornblende-ferrohornblende, Ca2[(Mg,Fe)4Al]Si7AlO22(OH)2
    • (Mg,Fe)4 equivalent to (Mg1-x,Fex)4
  • Tschermakite-ferrotschermakite, Ca2[(Mg,Fe)3Al2]Si6Al2O22(OH)2
    • (Mg,Fe)3 equivalent to (Mg1-x,Fex)3
  • Edenite-ferroedenite, NaCa2(Mg,Fe)5Si7AlO22(OH)2
    • (Mg,Fe)5 equivalent to (Mg1-x,Fex)5
  • Pargasite-ferropargasite, NaCa2[(Mg,Fe)4Al]Si6Al2O22(OH)2
    • (Mg,Fe)4 equivalent to (Mg1-x,Fex)4
  • Magnesiohastingstite-hastingsite, NaCa2[(Mg,Fe)4Fe3+]Si6Al2O22(OH)2
    • (Mg,Fe)4 equivalent to (Mg1-x,Fex)4

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!

Doesn't work for formulas with nested parenthesis

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

Vibrational states of polyatomic molecules

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.