def testFormGen():

    mf = "C6H12O3"
    m0 = mass.of(mf)

    t = ms.formulaTable(m0 - 0.001,
                        m0 + 0.001,
                        C=(0, 100),
                        H=(0, 100),
                        O=(0, 110),
                        N=0,
                        P=0,
                        S=0)
    assert len(t) == 1, len(t)
    assert t.mf.values == [mf]
    t = ms.formulaTable(m0 - 0.005,
                        m0 + 0.005,
                        C=(0, 100),
                        H=(0, 100),
                        O=(0, 110))
    t.print_()
    assert len(t) == 3, len(t)
    assert mf in t.mf.values
    assert "C2H8N6O" in t.mf.values
    assert "C5H13N2P" in t.mf.values
Beispiel #2
0
def testFormGen():

    mf = "C6H12O3"
    m0 = mass.of(mf)

    t = ms.formulaTable(m0-0.001, m0+0.001, C=(0,100), H=(0, 100), O=(0, 110), N=0, P=0, S=0)
    assert len(t) == 1, len(t)
    assert t.mf.values == [mf]
    t = ms.formulaTable(m0-0.005, m0+0.005, C=(0,100), H=(0, 100), O=(0, 110))
    t.print_()
    assert len(t) == 3, len(t)
    assert mf in t.mf.values
    assert "C2H8N6O" in t.mf.values
    assert "C5H13N2P" in t.mf.values
Beispiel #3
0
def testAccessAndConsistency():
    c12 = elements.C12
    assert c12["abundance"] == abundance.C12
    assert c12["abundance"] is not None
    assert abs(c12["abundance"] - 0.989) < 0.001
    assert c12["mass"] == mass.C12
    assert c12["name"] == "Carbon"
    assert c12["number"] == 6
    assert mass.of("[13]C") - mass.of("C") == mass.C13 - mass.C12
    assert mass.of("C", C=mass.C13) == mass.of("[13]C")
    assert mass.of("C", C=elements.C13) == mass.of("[13]C")
Beispiel #4
0
#encoding: latin-1

import mass as _mass

_all_adducts=[("M+H"      , _mass.p                    , 1),
              ("M+NH4"    , _mass.of("NH3") + _mass.p  , 1),
              ("M+Na"     , _mass.Na - _mass.e         , 1),
              ("M+H-2H2O" , _mass.p - 2*_mass.of("H2O"), 1),
              ("M+H-H2O"  , _mass.p - _mass.of("H20")  , 1),
              ("M+K"      , _mass.K - _mass.e          , 1),
              ("M+ACN+H"  , _mass.of("C2H3N") + _mass.p , 1),
              ("M+ACN+Na" , _mass.of("C2H3N") + _mass.Na - _mass.e , 1),
              ("M+2Na-H"  , _mass.of("Na2") - _mass.H - _mass.e, 1),
              ("M+2H"     , 2*_mass.p                 , 2),
              ("M+3H"     , 3*_mass.p                 , 3),
              ("M+H+Na"     , _mass.p + _mass.Na - _mass.e, 2),
              ("M+2H+Na"  , 2*_mass.p + _mass.Na - _mass.e, 3),
              ("M+2Na"    , 2*_mass.Na - 2*_mass.e    , 2),
              ("M+2Na+H"  , _mass.p + 2*_mass.Na - 2*_mass.e, 3),
              ("M+Li"      , _mass.Li - _mass.e          , 1),
              ("M+CH3OH+H", _mass.of("CH4O") + _mass.p , 1),

              ("M-H"      , -_mass.p                  , -1),
              ("M-H2O-H"  , -_mass.p - _mass.of("H2O"), -1),
              ("M+Na-2H"  , -2*_mass.p + _mass.Na     , -1),
              ("M+Cl"     , _mass.Cl + _mass.e  , -1),
              ("M+K-2H"   , -2*_mass.p + _mass.K      , -1),
              ("M+KCl-H"  , -1*_mass.p + _mass.K + _mass.Cl, -1),
              ("M+FA-H"   , _mass.of("H2CO2")-_mass.p , -1),
              ("M-2H"     , -2*_mass.p                 , -2),
              ("M-3H"     , -3*_mass.p                 , -3),
Beispiel #5
0
#encoding: latin-1

import mass as _mass

_all_adducts = [("[M+H]+", _mass.p, 1),
                ("[M+NH4]+", _mass.of("NH3") + _mass.p, 1),
                ("[M+Na]+", _mass.Na - _mass.e, 1),
                ("[M+H-H2O]+", _mass.p - _mass.of("H20"), 1),
                ("[M+H-H4O2]+", _mass.p - 2 * _mass.of("H2O"), 1),
                ("[M+K]+", _mass.K - _mass.e, 1),
                ("[M+CH4O+H]+", _mass.of("CH4O") + _mass.p, 1),
                ("[M+2Na-H]+", _mass.of("Na2") - _mass.H - _mass.e, 1),
                ("[M+H2]2+", 2 * _mass.p, 2), ("[M+H3]3+", 3 * _mass.p, 3),
                ("[M+Na+H]2+", _mass.p + _mass.Na - _mass.e, 2),
                ("[M+H2+Na]3+", 2 * _mass.p + _mass.Na - _mass.e, 3),
                ("[M+Na2]2+", 2 * _mass.Na - 2 * _mass.e, 2),
                ("[M+H+Na2]3+", _mass.p + 2 * _mass.Na - 2 * _mass.e, 3),
                ("[M-H]-", -_mass.p, -1),
                ("[M-H-H2O]-", -_mass.p - _mass.of("H2O"), -1),
                ("[M+Na-H2]-", -2 * _mass.p + _mass.Na, -1),
                ("[M+Cl]-", -(_mass.p - _mass.Cl), -1),
                ("[M+K-H2]-", -2 * _mass.p + _mass.K, -1),
                ("[M-H2]2-", -2 * _mass.p, -2), ("[M-H3]3-", -3 * _mass.p, -3)]


_shortname = lambda key: key[1:].split("]")[0].replace("+", "_plus_")\
                                              .replace("-", "_minus_")

labels = [_a[0] for _a in _all_adducts]
namedLabels = [_shortname(_a) for _a in labels]
Beispiel #6
0
#encoding: latin-1

import mass as _mass

_all_adducts = [("M+H", _mass.p, 1), ("M+NH4", _mass.of("NH3") + _mass.p, 1),
                ("M+Na", _mass.Na - _mass.e, 1),
                ("M+H-2H2O", _mass.p - 2 * _mass.of("H2O"), 1),
                ("M+H-H2O", -_mass.of("OH") - _mass.e, 1),
                ("M+K", _mass.K - _mass.e, 1),
                ("M+ACN+H", _mass.of("C2H3N") + _mass.p, 1),
                ("M+ACN+Na", _mass.of("C2H3N") + _mass.Na - _mass.e, 1),
                ("M+2Na-H", _mass.of("Na2") - _mass.H - _mass.e, 1),
                ("M+2H", 2 * _mass.p, 2), ("M+3H", 3 * _mass.p, 3),
                ("M+H+Na", _mass.p + _mass.Na - _mass.e, 2),
                ("M+2H+Na", 2 * _mass.p + _mass.Na - _mass.e, 3),
                ("M+2Na", 2 * _mass.Na - 2 * _mass.e, 2),
                ("M+2Na+H", _mass.p + 2 * _mass.Na - 2 * _mass.e, 3),
                ("M+Li", _mass.Li - _mass.e, 1),
                ("M+CH3OH+H", _mass.of("CH4O") + _mass.p, 1),
                ("M-H", -_mass.p, -1),
                ("M-H2O-H", -_mass.p - _mass.of("H2O"), -1),
                ("M+Na-2H", -2 * _mass.p + _mass.Na, -1),
                ("M+Cl", _mass.Cl + _mass.e, -1),
                ("M+K-2H", -2 * _mass.p + _mass.K, -1),
                ("M+KCl-H", -1 * _mass.p + _mass.K + _mass.Cl, -1),
                ("M+FA-H", _mass.of("H2CO2") - _mass.p, -1),
                ("M-2H", -2 * _mass.p, -2), ("M-3H", -3 * _mass.p, -3),
                ("M+CH3COO", _mass.of("H4C2O2") - _mass.p, -1),
                ("M+F", _mass.F - _mass.e, -1), ("M", 0.0, 0)]

_shortname = lambda key: key.replace("+", "_plus_").replace("-", "_minus_")
Beispiel #7
0
#encoding: latin-1

import mass as _mass

_all_adducts=[("[M+H]+"     , _mass.p                    , 1),
              ("[M+NH4]+"   , _mass.of("NH3") + _mass.p  , 1),
              ("[M+Na]+"    , _mass.Na - _mass.e         , 1),
              ("[M+H-H2O]+" , _mass.p - _mass.of("H20")  , 1),
              ("[M+H-H4O2]+", _mass.p - 2*_mass.of("H2O"), 1),
              ("[M+K]+"     , _mass.K - _mass.e          , 1),
              ("[M+CH4O+H]+", _mass.of("CH4O") + _mass.p , 1),
              ("[M+2Na-H]+" , _mass.of("Na2") - _mass.H - _mass.e, 1),
              ("[M+H2]2+"   , 2*_mass.p                 , 2),
              ("[M+H3]3+"   , 3*_mass.p                 , 3),
              ("[M+Na+H]2+" , _mass.p + _mass.Na - _mass.e, 2),
              ("[M+H2+Na]3+", 2*_mass.p + _mass.Na - _mass.e, 3),
              ("[M+Na2]2+"  , 2*_mass.Na - 2*_mass.e    , 2),
              ("[M+H+Na2]3+", _mass.p + 2*_mass.Na - 2*_mass.e, 3),
              ("[M-H]-"     , -_mass.p                  , -1),
              ("[M-H-H2O]-" , -_mass.p - _mass.of("H2O"), -1),
              ("[M+Na-H2]-" , -2*_mass.p + _mass.Na     , -1),
              ("[M+Cl]-"    , -(_mass.p - _mass.Cl)     , -1),
              ("[M+K-H2]-"  , -2*_mass.p + _mass.K      , -1),
              ("[M-H2]2-"   , -2*_mass.p                , -2),
              ("[M-H3]3-"   , -3*_mass.p                , -3)
             ]


_shortname = lambda key: key[1:].split("]")[0].replace("+", "_plus_")\
                                              .replace("-", "_minus_")