Package API

nist_elem

class tofsim.nist_elem.Sustancias(elementos='', threshold=0.0001, isotopes=True)

Bases: dict

Object describing a list of substances.

Examples

>>> elementos = ['N2', 'H2O', 'Ar^{3+}', 'Ar^{+}', 'Ar^2+', 'UF6']
>>> m = Sustancias(elementos, threshold=1.e-3)
>>> print(m)
l                     M          P
-------------  --------  ---------
1H2-16O^{+}     18.0106  99.7341
1H2-18O^{+}     20.0148   0.204953
14N2^{+}        28.0061  99.2733
14N-15N^{+}     29.0032   0.72535
36Ar^{3+}       35.9675   0.3365
36Ar^{+}        35.9675   0.3365
36Ar^{2+}       35.9675   0.3365
40Ar^{3+}       39.9624  99.6003
40Ar^{+}        39.9624  99.6003
40Ar^{2+}       39.9624  99.6003
19F6-235U^{+}  349.034    0.7204
19F6-238U^{+}  352.041   99.2742

To get help use:

>>> m.show_help()
Create an object Sustancias as:
#
  Sustancias(<elemento o sustancia>)
#
Fields in mass have the meaning:
#
 Z:  str  Atomic Number
 S:  str  Atomic Symbol
 A:  str  Mass Number
 M:  str  Relative Atomic Mass
 P:  str  Isotopic Composition
 W:  str  Standard Atomic Weight
 q:  str  Charge
add(sustancias)

Returns a dictionary with all the information on the substances added.

Parameters:sustancias (str) –

Comma separated list of substances to be added, por instance:

m = add(‘H20,O2,N2,UF5,UF6’)
copy()

Copy the object and returns a new one.

get_lista(cols=None)

Return a list with the cols

Parameters:cols (tuple/list or None) – A list of string selecting the fields to included, chosen from “A,L,l,M,P,S,Z”
list(key=None)

Return a list of elements, optionally filtered with a criteria given by key

Parameters:key (None or function) –
  • if key=None returns all elements
  • otherwise key has to be a function returning True or False.

Examples

>>> list(key = lambda x:  x['P'] > 0.40)  # returns True if population greater than 40%
>>> list(key = lambda x:  x['M'] > 50)    # returns True if Mass smaller than than 50 AMU
>>> list(key = lambda x:  x['q'] > 2)     # returns True if charge greater than 2
loadconf(fname)

Load substances from file

Parameters:fname (str or Path() object) – File with definition of substances to add

File should have configuration format as:

[34S1]
S=S
L=$^{34}\mathrm{S}$
P=4.25
M=33.9678669
A=34
Z=16

[32S1]
S=S
L=$^{32}\mathrm{S}$
P=94.99
M=31.972071
A=32
Z=16
remove(sustancias, criteria='fragment')

Remove a fragment

Parameters:
  • sustancias (str or list of strings) – substance or fragment to remove
  • criteria (str) – either ‘fragment’ (the default value) or ‘substance’:

For the choices of ‘criteria’, we use:

  • ‘fragment’: e.g: Ar^{2+}, SF6^++, Removes exactly the fragment given
  • ‘substance’: e.g: Ar, SF6, Xe, Remove all fragments with independently of the charge
saveconf(fname=None)

Save the substances to a file in a format that may be later read

Parameters:
  • self (type) – description
  • fname (None or str or pathlib.Path()) – Name of the file. If None prints to screen
show_help()

Show help on use of Object Sustancias

sort(order=None, reverse=False)

Sort the substances according to the specified order. The sort is stable.

Parameters:
  • self (type) – description
  • order (str) – desired order. One of ‘ALMPSZq’
  • reverse (bool) – If True will be reversed
to_latex(cols=None, headers=None, standalone=False)

Convert to LaTeX table using tabulate package

Parameters:
  • cols (list) – Substance characteristics to include.
  • headers (str) – String to write before data.
  • standalone (bool) – If True make a standalone document that may be compiled by LaTeX.
to_pdf(cols=None, headers=None, latexcommand='pdflatex', output='tmp.pdf')

Convert to pdf format using latex.

Export to a latex file and compiles it.

Parameters:
  • self (type) – description
  • cols (str) – Substance characteristics to include
  • headers (str) – Description to include before data
  • latexcommand (str) – command to compile to pdf
  • output (str) – Name of the output file
to_table(cols=None, headers=(), tablefmt='simple', floatfmt='g', numalign='decimal', stralign='left', missingval='')

Format the list of sustances in Table format.

This is a wrapper around the tabulate function from the tabulate package: https://pypi.python.org/pypi/tabulate. Available formats are: fancy_grid, grid, plain, psql, rst, simple, tsv latex, latex_raw, latex_booktabs, mediawiki, orgtbl, pipe, html

Options tablefmt, floatfmt, numalign, stralign, missingval are passed to package tabulate, if available.

Parameters:
  • cols (list) – A list of strings with the characteristics to include. Must be in ALMPSZ
  • headers (str) – String to include before data
  • tablefmt (str) – Format of table
  • floatfmt (str) – Format used to write numbers
  • numalign (str) – Alignment for numbers
  • stralign (str) – Alignment for strings
  • missingval (str) – Value to write when values are missing
to_text()

Convenience function to format as a simple table

tofsim.nist_elem.analyze_substance(subst, threshold=0.0001, fragments=False, isotopes=True)

Devuelve todas las combinaciones con posibles isotopos (y su poblacion) de la sustancia con la formula dada.

Parameters:
  • subst (str) – substance to include (H2O, CO, SF6, N2, …)
  • threshold (float) – Minimum abundance that has to have an isotope to be included
  • fragments (bool) – If True includes all fragments. For instance from ‘CO’ -> ‘CO’, ‘C’, ‘O’
  • isotopes (bool) – If True includes all isotope combinations

Examples:

analyze_substance('H2O').keys() =  ['1H1-2H1-16O1', '1H2-17O1', '1H2-16O1', '1H2-18O1']
analyze_substance('CO').keys() =
       ['13C1-17O1', '13C1-18O1', '12C1-16O1', '12C1-18O1', '13C1-16O1', '12C1-17O1']
tofsim.nist_elem.format_listmass(rows, end='\n', sep=' ', header='', footer='')

Simple formatting of a list of substances. It is intended to use with the output of get_lista()

Parameters:
  • rows (list) – List where each row is a list with data on a single element
  • end (str) – End of line string
  • sep (str) – string used as separator within a line
  • header (str) – Header to add before the data
  • footer (str) – Footer to add after the data
tofsim.nist_elem.loadmass(fname)

Load masses from configuration file

Parameters:fname (str or Path()) – File to read masses from
Returns:a dictionary with the elements read
Return type:dict
tofsim.nist_elem.make_label(ss, fmt='key')

Construct the label for a given substance

Parameters:
  • ss (str) – Array of tuples [(A1,S1), (A2,S2), …] for all atoms in the substance
  • fmt (str) –

    Indicates the format of labels:

    'key'         -> "14N2"
    'Latex'       -> "$^{14}N_{2}$"
    'latexsimple' -> "$N_{2}$"
    'latexdoc'    -> r"\ce{^{14}N_{2}}"
    'mass'        -> "28"
    
tofsim.nist_elem.mass2conf(masses)

Format masses for a configuration file

Parameters:masses (dict) – Information on substance(s)
Returns:string with the format of a configuration file
Return type:str
tofsim.nist_elem.read_nist_data(threshold=0)

Read data from file datafile and fills the dictionary __NIST_ELEMENTS__ with all the data

Parameters:threshold (float) – Add all elements whose abundance is higher than threshold

tof

class tofsim.tof.Peaks

Bases: dict

Simple object describing spectra peaks for the TOF.

It is essentially a dictionary, with a few added convenience methods

Each peak is described by a dictionary whose key is the label of the fragment.

The values are:

  • ‘index’: tuple
    has the form (im, i0, ip) with the indexes of the peak (i0) and the two positions where the width is obtained.
  • ‘position’: float
    is value of the coordinate where the peak is located, in microseconds.
  • ‘height’: float
    is the value of the peak.
  • ‘width’: float
    is the width of the peak in microseconds.
tolist()

Returns a list with the data describing the peaks. The form is: [‘Substance’, ‘index’, ‘position’, ‘height’, ‘width’]

class tofsim.tof.ToF(substances=None, **kwds)

Bases: object

The ToF object defines and handles all aspects of a Time-of-Flight spectrometer

The following parameters related to the construction and operation are included: Distances, voltages, working temperature, particle velocity fields and dispersion, time duration and size of the ionizing beam are also included.

Examples

tof_parameters= {
  's': 0.7,                    # Distance from center to first plate in cm
  'd': 2.54,                   # Distance between plates in cm (second stage)
  'D': 100.,                   # Distance of free flight
  'Vs': 500,                   # Potential Es in eV
  'Vd': 1900,                  # Potential Ed in eV
  'ds': 0.05,                  # Radio del spot del laser in cm
  'dt': 0.008,                 # Laser-pulse duration
  't0': 0.,                    # Offset in time of TOF (experimental)
  'r0': 1.e3,                  # Aperture radius after extraction
  }

# We can create the object with the parameters desired
T = ToF(['Ar', 'N2', 'CO2'],**tof_parameters)

# We can also load parameters from a file
T.load_conf_file('tof.conf')

T.signal()     # Calculate the signals

# Plot the signals
T.make_plot(fname='tof2.png', negative=True, show_legend=True, show_all=True)

# Just printing the object gives all the information on construction and
# condition parameters as well as the substances being simulated
print(T)
add_substances(substances, threshold=0.001)

Add substances to be simulated.

Parameters:
  • substances (str) – Comma-separated string, or list of strings, each substance may have the form SF5^{+}, SF5^{++}, SF5^+, S^2+
  • threshold (float) – Minimum abundance of a given isotope to be included (default 1.e-3).
calc_signal(particles, Time)

Calculo de los histogramas para generar la señal de un grupo de partículas

data_to_array(unpack=False)

Conversion from signal to “numpy arrays”, sorted by time

Keyword Arguments: unpack – (default False)

get_statistics_peaks(substances='all', fwidth=0.36787944117144233)

Find peaks

Parameters:
  • substances ('all' or list) –
    • if ‘all’ find the peak for every fragment in the TOF
    • if substance is a list of strings, each element must be a fragment in TOF
  • fwidth (float) – fraction of the maximum at which to evaluate the full width. For instance, fwidth = 0.5 corresponds to FWHM
get_tof_parameters(explain=False)

Returns the parameters of TOF in a dict.

Parameters:
  • self (type) – description
  • explain (bool) – If True add an ascii graphic with the diagram of the TOF
load_conf_file(fname)

Load a configuration file, update tof parameters, and also return masses if present.

make_plot(especies=None, fname=None, **kvars)

Plot the signals in a “standard” form.

Parameters:
  • especies (dict) – masses to plot. If no present uses simulated fragments
  • fname (string or None (default None)) – if not None -> Save the figure to “fname”
  • kvars (Optional) –
    • negative = True/False : if True -> Negative signal
    • graph_all=`True/False` (or show_all): if True -> Plot individual species
    • show_legend=`True/False` : if True -> Show the legend
mean_times(x0=0.0)

Evaluate the ‘main’ time of each species, given as if generated in ideal conditions:

  • At time t=0
  • At rest (null initial velocity)
  • At a distance x0 from the center of the extraction plates (s = 0)
remove_substances(sustancias)

Remove substances from the simulation

Parameters:
  • self (type) – description
  • sustancias (str or list of strings) – substances or fragments to remove
save_conf_file(fname, masas={})

Save configuration data for tof and masses to a file

save_data(fname)

Save the signal to a data file

set_initial_distribution()

Initial velocity and position distributions

signal(particles=None)

Evaluate the signal that would produce the particles in the ToF

Parameters:
  • particles (dict each item is a dictionary that should have) –
    • key: is the label of the mass
    • ’M’: Mass (in AMU)
    • ’P’: (float in range 0 to 1) Abundance
    • ’L’: an (optional, possibly formatted) label, otherwise the key is used
  • particles is None => Usa los fragments (If) –
Returns:

times – Sets the object variable self.times and also returns its value

Return type:

numpy array

time_of_extract(x_0, v_0)

Evaluates the time taken to extract a particle of mass M=1 and charge q=1 with initial velocity v_0 and position x_0 from the extraction plates.

time_of_flight(x_0, v_0)

Evaluates the time-of-flight of a particle of mass M=1 and charge q=1 with initial velocity v_0 and position x_0.

time_of_flight_bibliog(x_0, v_0)

Alternative evaluatation of time-of-flight of a particle of mass M=1 and charge q=1 with initial velocity v_0 and position x_0 (from bibliography).

tofsim.tof.get_one_peak(x, y, fwidth=0.36787944117144233)

Returns features of a single peak.

Returns a list with:

  • Position 0: indexes of position of:
    • lower half height
    • center
    • upper half height
  • Position 1: values of x
  • Position 2: values of y