def test_formula(self): assert Molecule( name="Dimethyl Phthalate", formula="C10 H10 O4" ).formula == Formula({'C': 10, 'H': 10, 'O': 4}) assert Molecule( name="Dimethyl Phthalate", formula=Formula({'C': 10, 'H': 10, 'O': 4}) ).formula == Formula({'C': 10, 'H': 10, 'O': 4}) assert Molecule(name="Dimethyl Phthalate").formula == Formula()
def test_matches(self): molecule = Molecule( name="Dimethyl Phthalate", matches={ "overall": Score(62.90), "tgt": Score(62.90, flag_string="low score", flag_severity=2), }, ) assert molecule.matches == { "overall": Score(62.90), "tgt": Score(62.90, flag_string="low score", flag_severity=2), } with pytest.raises(TypeError, match="'matches' must be a dictionary, not"): Molecule(name="Dimethyl Phthalate", matches="Hello World") # type: ignore
def test_repr(): molecule = Molecule( name="Dimethyl Phthalate", formula="C10 H10 O4", matches={ "overall": Score(62.90), "tgt": Score(62.90, flag_string="low score", flag_severity=2), }, ) assert str(molecule) == "Molecule(Dimethyl Phthalate, C10H10O4)" assert repr(molecule) == "<Molecule(Dimethyl Phthalate, Formula({'C': 10, 'H': 10, 'O': 4}))>"
def expected_compound(fbf_spectrum, tof_spectrum): score = Score(99.79) return Compound( algo="FindByFormula", location={'m': 169.0893, "rt": 13.649, 'a': 29388223, 'y': 3377289}, compound_scores={"fbf": score}, results=[ Molecule( name="Diphenylamine", formula="C12 H11 N", matches={ "overall": score, "tgt": score, } ) ], spectra=[fbf_spectrum, tof_spectrum], )
def test_dict(): assert dict( Molecule( name="Dimethyl Phthalate", formula="C10 H10 O4", matches={ "overall": Score(62.90), "tgt": Score(62.90, flag_string="low score", flag_severity=2), }, ) ) == { "name": "Dimethyl Phthalate", "formula": Formula({'C': 10, 'H': 10, 'O': 4}), "matches": { "overall": Score(62.90), "tgt": Score(62.90, flag_string="low score", flag_severity=2), }, }
def molecule(): return Molecule(name="Dimethyl Phthalate", formula="C10 H10 O4")
def test_from_xml(raw_xml, expects): tree = lxml.objectify.fromstring(raw_xml) spec = Molecule.from_xml(tree) assert spec == expects
def test_name(self): assert Molecule(name="Dimethyl Phthalate").name == "Dimethyl Phthalate"
assert repr(molecule) == "<Molecule(Dimethyl Phthalate, Formula({'C': 10, 'H': 10, 'O': 4}))>" raw_xml = """ <Molecule name="Dimethyl Phthalate" formula="C10 H10 O4"> <MatchScores> <Match algo="overall" score="62.90" /> <Match algo="tgt" score="62.90" tgtFlagsString="low score" tgtFlagsSeverity="2" /> </MatchScores> </Molecule> """ expects = Molecule( name="Dimethyl Phthalate", formula="C10 H10 O4", matches={ "overall": Score(62.90), "tgt": Score(62.90, flag_string="low score", flag_severity=2), }, ) @pytest.mark.parametrize("raw_xml, expects", [(raw_xml, expects)]) def test_from_xml(raw_xml, expects): tree = lxml.objectify.fromstring(raw_xml) spec = Molecule.from_xml(tree) assert spec == expects raw_xml_1 = '<MatchScores><Match algo="fbf" score="86.30" /></MatchScores>' raw_xml_2 = '<MatchScores><Match algo="fbf" score="56.24" tgtFlagsString="low score; No H adduct" tgtFlagsSeverity="2" /></MatchScores>' raw_xml_3 = '<MatchScores><Match algo="fbf" score="82.53" tgtFlagsString="No H adduct" tgtFlagsSeverity="2" /></MatchScores>'