Git Product home page Git Product logo

atomphys's People

Contributors

mgrau avatar wipfli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

atomphys's Issues

Nonzero dipole matrix element for forbidden transitions

For a dipole-forbidden transition in $\mathrm{Ca}^+$ ion (and I guess, for many other Atoms), the matrix_element attribute is unexpectedly nonzero:

>>> Ca_plus = Atom('Ca+')
>>> Ca_plus('4S1/2').to('3D5/2').matrix_element.to('e a0').m
0.0012221264747753456

I guess that the problem originates from the fact that the code doesn't try to distinguish between dipole-allowed and dipole-forbidden transitions. It and always calculates matrix element from lifetime using the dipole formula, whereas it is not valid for quadrupole and higher-order transitions.

Error in retrieving data from NIST

The error

I installed atomphys and failed to run the example from README.md:

>>> from atomphys import Atom
>>> Rb = Atom('Rb')

This code resulted in an error:

Traceback (most recent call last):
  File "/home/evgeny/work/other_studies/programming_notes/atomic_physics_mgrau/src/atomphys/atomphys/atom.py", line 40, in __init__
    self.load(atom)
  File "/home/evgeny/work/other_studies/programming_notes/atomic_physics_mgrau/src/atomphys/atomphys/atom.py", line 92, in load
    with open(filename) as file:
FileNotFoundError: [Errno 2] No such file or directory: 'Rb'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    Rb = Atom('Rb', refresh_cache=True)
  File "/home/evgeny/work/other_studies/programming_notes/atomic_physics_mgrau/src/atomphys/atomphys/atom.py", line 42, in __init__
    self.load_nist(atom, refresh_cache)
  File "/home/evgeny/work/other_studies/programming_notes/atomic_physics_mgrau/src/atomphys/atomphys/atom.py", line 114, in load_nist
    self._load_states(nist.parse_states(nist.fetch_states(atom, refresh_cache)))
  File "/home/evgeny/work/other_studies/programming_notes/atomic_physics_mgrau/src/atomphys/atomphys/data/nist.py", line 55, in parse_states
    return [
  File "/home/evgeny/work/other_studies/programming_notes/atomic_physics_mgrau/src/atomphys/atomphys/data/nist.py", line 70, in <listcomp>
    if print_term(state["Term"], J=state["J"])
KeyError: 'Term'

The solution

In nist.py, change the options in values dictionary (line 27) to the following:

    values = {
        "spectrum": atom,
        "units": 2,  # energy units {0: cm^-1, 1: eV, 2: Ry}
        "format": 3,  # format {0: HTML, 1: ASCII, 2: CSV, 3: TSV}
        "multiplet_ordered": 1,  # energy ordred
        "term_out": "on",  # output the term symbol string
        "conf_out": "on",  # output the configutation string
        "level_out": "on",  # output the energy level
        "unc_out": 1,  # uncertainty on energy # --- changed 0 to 1
        "j_out": "on",  # output the J level
        "g_out": "on",  # output the g-factor
        "lande_out": "on",  # output experimentally measured g-factor # changed from "off" to "on"
    }

Comment

I discovered that the error is caused by incorrect data retrieval from NIST. In fetch_states in nist.py, the URL request constructed from the values dictionary is not correctly processed by https://physics.nist.gov. Instead of a .tsv with the energy levels, https://physics.nist.gov returns the error page "Invalid Column Setting". The example URL request generated by current code version and causing error:

https://physics.nist.gov/cgi-bin/ASD/energy1.pl?spectrum=rb+i&units=2&format=3&multiplet_ordered=1&term_out=on&conf_out=on&level_out=on&unc_out=0&j_out=on&g_out=on&lande_out=off

Changing the options to lande_out=on and unc_out=1 yields the correct result.

Typo readme

print(Rb('S1/2').to('P1/2').λ.to('nm'))

returns 795 nm and not 785 nm as stated in the readme.

error fetching atom

atom.Atom('H',refresh_cache=True)
     59     return [
     60         {
     61             **{
     62                 "energy": remove_annotations(state["Level (Ry)"]) + " Ry",
     63                 "term": print_term(state["Term"], J=state["J"]),
     64                 "configuration": state["Configuration"],
     65                 "g": None if state["g"] == "" else float(state["g"]),
     66             },
     67             **(
     68                 {"n": int(monovalent.match(state["Configuration"])["n"])}
     69                 if monovalent.match(state["Configuration"])
     70                 else {}
     71             ),
     72         }
     73 
     74         for state in data
---> 75         if print_term(state["Term"], J=state["J"])
     76     ]

KeyError: 'Term'

It seems that the parameter land_out=off results in invalid column settings for the nist website which breaks the fetching procedure.
Replacing land_out=on seems to fix it.

Polarizability cannot be calculated for J=0 state

The polarizability for J = 0 states cannot be calculated due to a divide by zero in the calculation of the prefactor for the vector polarizability

C1 = A * cos(θk) * mJ / J

A J = 0 state does not have a vector polarizability since the Clebsch-Gordan coefficient <J=0, mj; 1, 0| J=0, mj> = 0 appearing in eq. (10) of http://dx.doi.org/10.1140/epjd/e2013-30729-x is zero.
Therefore,

if J == 0:
    C1 = 0
else:
    C1 = A * cos(θk) * mJ / J 

solves the problem.

Caching of data

At the moment data has to be always fetched from the NIST database when the Atom class is initialized. There are functions for caching the data but loading is not possible (ValueError: could not convert string to float: '0 E_h'). As a result atomphys is not usable offline or when the NIST database is not accessible.

Proposed changes:

  • Fix atom.load to correctly load cached data.
  • Automatically cache data and use it as a fallback (or default) option when initializing the Atom class.

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.