Esempio n. 1
0
	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()
Esempio n. 2
0
	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
Esempio n. 3
0
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}))>"
Esempio n. 4
0
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],
			)
Esempio n. 5
0
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),
							},
					}
Esempio n. 6
0
def molecule():
	return Molecule(name="Dimethyl Phthalate", formula="C10 H10 O4")
Esempio n. 7
0
def test_from_xml(raw_xml, expects):
	tree = lxml.objectify.fromstring(raw_xml)
	spec = Molecule.from_xml(tree)
	assert spec == expects
Esempio n. 8
0
	def test_name(self):
		assert Molecule(name="Dimethyl Phthalate").name == "Dimethyl Phthalate"
Esempio n. 9
0
	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>'