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