def test_can_get_all_external_pdbs(self, mock_xml_retriever, mock_simple_retriever, mock_json_retriever): mock_json_retriever.return_value = {"smiles": "CCC", "inchi": "CCC", "oneLetterSeq": "CCC"} mock_simple_retriever.return_value = ElementTree.fromstring('''<?xml version='1.0' standalone='no' ?> <smilesQueryResult smiles="NC(=O)C1=CC=CC=C1" search_type="4"> <ligandInfo> <ligand structureId="2XG3" chemicalID="UNU" type="non-polymer" molecularWeight="121.137"> <chemicalName>BENZAMIDE</chemicalName> <formula>C7 H7 N O</formula> <InChIKey>KXDAEFPNCMNJSK-UHFFFAOYSA-N</InChIKey> <InChI>InChI=1S/C7H7NO/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H2,8,9)</InChI> <smiles>c1ccc(cc1)C(=O)N</smiles> </ligand> <ligand structureId="3A1I" chemicalID="UNU" type="non-polymer" molecularWeight="121.137"> <chemicalName>BENZAMIDE</chemicalName> <formula>C7 H7 N O</formula> <InChIKey>KXDAEFPNCMNJSK-UHFFFAOYSA-N</InChIKey> <InChI>InChI=1S/C7H7NO/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H2,8,9)</InChI> <smiles>c1ccc(cc1)C(=O)N</smiles> </ligand> </ligandInfo> </smilesQueryResult>''') mock_xml_retriever.side_effect = [["1xxx", "3A1I"], ["2xxx"], ["2xxx"]] ligand = Ligand(self.ligand_json) pdbs = ligand.all_external_pdbs() self.assertEqual(len(pdbs), 4) for code in ["2XG3", "3A1I", "1xxx", "2xxx"]: self.assertIn(code, pdbs)
def test_can_get_sequence_pdbs(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.return_value = {"oneLetterSeq": "CCC"} mock_xml_retriever.return_value = ["2XG3", "3A1I"] ligand = Ligand(self.ligand_json) pdbs = ligand.sequence_pdbs() self.assertEqual(pdbs, ["2XG3", "3A1I"])
def test_structural_properties(self, mock_json_retriever): mock_json_retriever.return_value = { "iupacName": "2,3-dihydro-1,4-benzodioxin", "smiles": "OC[C@H]1COc2c(O1)cccc2N1CCN(CC1)CCNC(=O)c1ccc(cc1)F", "inchi": "InChI=1S/C22H26FN3O4/c23-17-6-4-16(5-7-17)22(28)24-8-9-25-10", "inchiKey": "NYSDRDDQELAVKP-SFHVURJKSA-N", "oneLetterSeq": "ILK", "threeLetterSeq": "Ile-Leu-Lys", "postTranslationalModifications": "Glycosylation", "chemicalModifications": "Methylation" } ligand = Ligand(self.ligand_json) self.assertEqual(ligand.iupac_name(), "2,3-dihydro-1,4-benzodioxin") self.assertEqual( ligand.smiles(), "OC[C@H]1COc2c(O1)cccc2N1CCN(CC1)CCNC(=O)c1ccc(cc1)F") self.assertEqual( ligand.inchi(), "InChI=1S/C22H26FN3O4/c23-17-6-4-16(5-7-17)22(28)24-8-9-25-10") self.assertEqual(ligand.inchi_key(), "NYSDRDDQELAVKP-SFHVURJKSA-N") self.assertEqual(ligand.one_letter_sequence(), "ILK") self.assertEqual(ligand.three_letter_sequence(), "Ile-Leu-Lys") self.assertEqual(ligand.post_translational_modifications(), "Glycosylation") self.assertEqual(ligand.chemical_modifications(), "Methylation")
def test_can_get_smiles_pdbs(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.return_value = {"smiles": "CCC"} mock_xml_retriever.return_value = ElementTree.fromstring( '''<?xml version='1.0' standalone='no' ?> <smilesQueryResult smiles="NC(=O)C1=CC=CC=C1" search_type="4"> <ligandInfo> <ligand structureId="2XG3" chemicalID="UNU" type="non-polymer" molecularWeight="121.137"> <chemicalName>BENZAMIDE</chemicalName> <formula>C7 H7 N O</formula> <InChIKey>KXDAEFPNCMNJSK-UHFFFAOYSA-N</InChIKey> <InChI>InChI=1S/C7H7NO/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H2,8,9)</InChI> <smiles>c1ccc(cc1)C(=O)N</smiles> </ligand> <ligand structureId="3A1I" chemicalID="UNU" type="non-polymer" molecularWeight="121.137"> <chemicalName>BENZAMIDE</chemicalName> <formula>C7 H7 N O</formula> <InChIKey>KXDAEFPNCMNJSK-UHFFFAOYSA-N</InChIKey> <InChI>InChI=1S/C7H7NO/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H2,8,9)</InChI> <smiles>c1ccc(cc1)C(=O)N</smiles> </ligand> </ligandInfo> </smilesQueryResult>''') ligand = Ligand(self.ligand_json) pdbs = ligand.smiles_pdbs() self.assertEqual(pdbs, ["2XG3", "3A1I"])
def test_can_get_gtop_pdbs(self, mock_json_retriever): self.interaction_json["ligandId"] = 149 mock_json_retriever.side_effect = [[self.interaction_json], self.pdb_json] ligand = Ligand(self.ligand_json) pdbs = ligand.gtop_pdbs() self.assertEqual(pdbs, ["4IAR"])
def test_interaction_id_id_must_be_int(self, mock_json_retriever): mock_json_retriever.return_value = [ self.interaction_json, self.interaction_json ] ligand = Ligand(self.ligand_json) with self.assertRaises(TypeError): ligand.get_interaction_by_id("1")
def test_can_get_inchi_pdbs_when_no_results(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.return_value = {"inchi": "CCC"} mock_xml_retriever.return_value = None ligand = Ligand(self.ligand_json) pdbs = ligand.inchi_pdbs() self.assertEqual(pdbs, [])
def test_can_get_sequence_pdbs_when_no_results(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.return_value = {"oneLetterSeq": "CCC"} mock_xml_retriever.return_value = None ligand = Ligand(self.ligand_json) pdbs = ligand.sequence_pdbs() self.assertEqual(pdbs, [])
def test_can_get_all_external_pdbs(self, mock_xml_retriever, mock_simple_retriever, mock_json_retriever): mock_json_retriever.return_value = { "smiles": "CCC", "inchi": "CCC", "oneLetterSeq": "CCC" } mock_simple_retriever.return_value = ElementTree.fromstring( '''<?xml version='1.0' standalone='no' ?> <smilesQueryResult smiles="NC(=O)C1=CC=CC=C1" search_type="4"> <ligandInfo> <ligand structureId="2XG3" chemicalID="UNU" type="non-polymer" molecularWeight="121.137"> <chemicalName>BENZAMIDE</chemicalName> <formula>C7 H7 N O</formula> <InChIKey>KXDAEFPNCMNJSK-UHFFFAOYSA-N</InChIKey> <InChI>InChI=1S/C7H7NO/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H2,8,9)</InChI> <smiles>c1ccc(cc1)C(=O)N</smiles> </ligand> <ligand structureId="3A1I" chemicalID="UNU" type="non-polymer" molecularWeight="121.137"> <chemicalName>BENZAMIDE</chemicalName> <formula>C7 H7 N O</formula> <InChIKey>KXDAEFPNCMNJSK-UHFFFAOYSA-N</InChIKey> <InChI>InChI=1S/C7H7NO/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H2,8,9)</InChI> <smiles>c1ccc(cc1)C(=O)N</smiles> </ligand> </ligandInfo> </smilesQueryResult>''') mock_xml_retriever.side_effect = [["1xxx", "3A1I"], ["2xxx"], ["2xxx"]] ligand = Ligand(self.ligand_json) pdbs = ligand.all_external_pdbs() self.assertEqual(len(pdbs), 4) for code in ["2XG3", "3A1I", "1xxx", "2xxx"]: self.assertIn(code, pdbs)
def test_can_get_interactions(self, mock_json_retriever): mock_json_retriever.return_value = [self.interaction_json, self.interaction_json] ligand = Ligand(self.ligand_json) interactions = ligand.interactions() self.assertIsInstance(interactions, list) self.assertEqual(len(interactions), 2) for interaction in interactions: self.assertIsInstance(interaction, Interaction)
def test_can_get_prodrugs(self, mock_json_retriever): mock_json_retriever.return_value = self.ligand_json ligand = Ligand(self.ligand_json) prodrugs = ligand.prodrugs() self.assertIsInstance(prodrugs, list) self.assertEqual(len(prodrugs), len(self.ligand_json["prodrugIds"])) for prodrug in prodrugs: self.assertIsInstance(prodrug, Ligand)
def test_can_get_complexes(self, mock_json_retriever): mock_json_retriever.return_value = self.ligand_json ligand = Ligand(self.ligand_json) complexes = ligand.complexes() self.assertIsInstance(complexes, list) self.assertEqual(len(complexes), len(self.ligand_json["complexIds"])) for complex_ in complexes: self.assertIsInstance(complex_, Ligand)
def test_can_get_subunits(self, mock_json_retriever): mock_json_retriever.return_value = self.ligand_json ligand = Ligand(self.ligand_json) subunits = ligand.subunits() self.assertIsInstance(subunits, list) self.assertEqual(len(subunits), len(self.ligand_json["subunitIds"])) for subunit in subunits: self.assertIsInstance(subunit, Ligand)
def test_can_get_active_drugs(self, mock_json_retriever): mock_json_retriever.return_value = self.ligand_json ligand = Ligand(self.ligand_json) active_drugs = ligand.active_drugs() self.assertIsInstance(active_drugs, list) self.assertEqual(len(active_drugs), len(self.ligand_json["activeDrugIds"])) for active_drug in active_drugs: self.assertIsInstance(active_drug, Ligand)
def test_can_get_interaction_by_id(self, mock_json_retriever): mock_json_retriever.return_value = [ self.interaction_json, self.interaction_json ] ligand = Ligand(self.ligand_json) interaction = ligand.get_interaction_by_id( self.interaction_json["interactionId"]) self.assertIsInstance(interaction, Interaction)
def test_synonym_properties(self, mock_json_retriever): mock_json_retriever.return_value = [ {"name": "DU-29,373", "refs": []}, {"name": "(+)-flesinoxan", "refs": []} ] ligand = Ligand(self.ligand_json) self.assertEqual(ligand.synonyms(), ["DU-29,373", "(+)-flesinoxan"])
def test_can_get_targets(self, mock_json_retriever): mock_json_retriever.side_effect = [ [self.interaction_json, self.interaction_json], self.target_json, self.target_json ] ligand = Ligand(self.ligand_json) targets = ligand.targets() self.assertIsInstance(targets, list) self.assertEqual(len(targets), 2) for target in targets: self.assertIsInstance(target, Target)
def test_can_get_interactions(self, mock_json_retriever): mock_json_retriever.return_value = [ self.interaction_json, self.interaction_json ] ligand = Ligand(self.ligand_json) interactions = ligand.interactions() self.assertIsInstance(interactions, list) self.assertEqual(len(interactions), 2) for interaction in interactions: self.assertIsInstance(interaction, Interaction)
def test_can_get_targets(self, mock_json_retriever): mock_json_retriever.side_effect = [[ self.interaction_json, self.interaction_json ], self.target_json, self.target_json] ligand = Ligand(self.ligand_json) targets = ligand.targets() self.assertIsInstance(targets, list) self.assertEqual(len(targets), 2) for target in targets: self.assertIsInstance(target, Target)
def test_structural_properties(self, mock_json_retriever): mock_json_retriever.return_value = { "iupacName": "2,3-dihydro-1,4-benzodioxin", "smiles": "OC[C@H]1COc2c(O1)cccc2N1CCN(CC1)CCNC(=O)c1ccc(cc1)F", "inchi": "InChI=1S/C22H26FN3O4/c23-17-6-4-16(5-7-17)22(28)24-8-9-25-10", "inchiKey": "NYSDRDDQELAVKP-SFHVURJKSA-N", "oneLetterSeq": "ILK", "threeLetterSeq": "Ile-Leu-Lys", "postTranslationalModifications": "Glycosylation", "chemicalModifications": "Methylation" } ligand = Ligand(self.ligand_json) self.assertEqual(ligand.iupac_name(), "2,3-dihydro-1,4-benzodioxin") self.assertEqual( ligand.smiles(), "OC[C@H]1COc2c(O1)cccc2N1CCN(CC1)CCNC(=O)c1ccc(cc1)F" ) self.assertEqual( ligand.inchi(), "InChI=1S/C22H26FN3O4/c23-17-6-4-16(5-7-17)22(28)24-8-9-25-10" ) self.assertEqual(ligand.inchi_key(), "NYSDRDDQELAVKP-SFHVURJKSA-N") self.assertEqual(ligand.one_letter_sequence(), "ILK") self.assertEqual(ligand.three_letter_sequence(), "Ile-Leu-Lys") self.assertEqual( ligand.post_translational_modifications(), "Glycosylation" ) self.assertEqual(ligand.chemical_modifications(), "Methylation")
def test_structural_properties_when_no_json(self, mock_json_retriever): mock_json_retriever.return_value = None ligand = Ligand(self.ligand_json) self.assertIs(ligand.iupac_name(), None) self.assertIs(ligand.smiles(), None) self.assertIs(ligand.inchi(), None) self.assertIs(ligand.inchi_key(), None) self.assertIs(ligand.one_letter_sequence(), None) self.assertIs(ligand.three_letter_sequence(), None) self.assertIs(ligand.post_translational_modifications(), None) self.assertIs(ligand.chemical_modifications(), None)
def test_synonym_properties(self, mock_json_retriever): mock_json_retriever.return_value = [{ "name": "DU-29,373", "refs": [] }, { "name": "(+)-flesinoxan", "refs": [] }] ligand = Ligand(self.ligand_json) self.assertEqual(ligand.synonyms(), ["DU-29,373", "(+)-flesinoxan"])
def test_molecular_properties_when_no_json(self, mock_json_retriever): mock_json_retriever.return_value = None ligand = Ligand(self.ligand_json) self.assertEqual(ligand.hydrogen_bond_acceptors(), None) self.assertEqual(ligand.hydrogen_bond_donors(), None) self.assertEqual(ligand.rotatable_bonds(), None) self.assertEqual(ligand.topological_polar_surface_area(), None) self.assertEqual(ligand.molecular_weight(), None) self.assertEqual(ligand.log_p(), None) self.assertEqual(ligand.lipinski_rules_broken(), None)
def test_database_properties(self, mock_json_retriever): mock_json_retriever.return_value = [ { "accession": "CHEMBL1742477", "database": "ChEMBL Ligand", "url": "http://www.ebi.ac.uk/chembldb/index.php/compound/inspect/CHEMBL1742477", "species": "None" }, { "accession": "57347", "database": "PubChem CID", "url": "http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=57347", "species": "None" } ] ligand = Ligand(self.ligand_json) self.assertEqual(len(ligand.database_links()), 2) self.assertIsInstance(ligand.database_links()[0], DatabaseLink) self.assertIsInstance(ligand.database_links()[1], DatabaseLink) self.assertEqual(ligand.database_links()[0].accession(), "CHEMBL1742477") self.assertEqual(ligand.database_links()[1].accession(), "57347")
def test_molecular_properties(self, mock_json_retriever): mock_json_retriever.return_value = { "hydrogenBondAcceptors": 5, "hydrogenBondDonors": 2, "rotatableBonds": 7, "topologicalPolarSurfaceArea": 74.27, "molecularWeight": 415.19073474, "logP": 1.84, "lipinskisRuleOfFive": 0 } ligand = Ligand(self.ligand_json) self.assertEqual(ligand.hydrogen_bond_acceptors(), 5) self.assertEqual(ligand.hydrogen_bond_donors(), 2) self.assertEqual(ligand.rotatable_bonds(), 7) self.assertEqual(ligand.topological_polar_surface_area(), 74.27) self.assertEqual(ligand.molecular_weight(), 415.19073474) self.assertEqual(ligand.log_p(), 1.84) self.assertEqual(ligand.lipinski_rules_broken(), 0)
def test_can_get_smiles_pdbs(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.return_value = {"smiles": "CCC"} mock_xml_retriever.return_value = ElementTree.fromstring('''<?xml version='1.0' standalone='no' ?> <smilesQueryResult smiles="NC(=O)C1=CC=CC=C1" search_type="4"> <ligandInfo> <ligand structureId="2XG3" chemicalID="UNU" type="non-polymer" molecularWeight="121.137"> <chemicalName>BENZAMIDE</chemicalName> <formula>C7 H7 N O</formula> <InChIKey>KXDAEFPNCMNJSK-UHFFFAOYSA-N</InChIKey> <InChI>InChI=1S/C7H7NO/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H2,8,9)</InChI> <smiles>c1ccc(cc1)C(=O)N</smiles> </ligand> <ligand structureId="3A1I" chemicalID="UNU" type="non-polymer" molecularWeight="121.137"> <chemicalName>BENZAMIDE</chemicalName> <formula>C7 H7 N O</formula> <InChIKey>KXDAEFPNCMNJSK-UHFFFAOYSA-N</InChIKey> <InChI>InChI=1S/C7H7NO/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H2,8,9)</InChI> <smiles>c1ccc(cc1)C(=O)N</smiles> </ligand> </ligandInfo> </smilesQueryResult>''') ligand = Ligand(self.ligand_json) pdbs = ligand.smiles_pdbs() self.assertEqual(pdbs, ["2XG3", "3A1I"])
def test_can_create_ligand(self): ligand = Ligand(self.ligand_json) self.assertEqual(ligand.json_data, self.ligand_json) self.assertEqual(ligand._ligand_id, 1) self.assertEqual(ligand._name, "flesinoxan") self.assertEqual(ligand._abbreviation, "flexo") self.assertEqual(ligand._inn, "flesinoxan") self.assertEqual(ligand._ligand_type, "Synthetic organic") self.assertEqual(ligand._species, None) self.assertEqual(ligand._radioactive, False) self.assertEqual(ligand._labelled, True) self.assertEqual(ligand._approved, True) self.assertEqual(ligand._withdrawn, False) self.assertEqual(ligand._approval_source, "FDA (1997)") self.assertEqual(ligand._subunit_ids, [2, 3]) self.assertEqual(ligand._complex_ids, [5]) self.assertEqual(ligand._prodrug_ids, [7]) self.assertEqual(ligand._active_drug_ids, [9, 10])
def test_database_properties(self, mock_json_retriever): mock_json_retriever.return_value = [{ "accession": "CHEMBL1742477", "database": "ChEMBL Ligand", "url": "http://www.ebi.ac.uk/chembldb/index.php/compound/inspect/CHEMBL1742477", "species": "None" }, { "accession": "57347", "database": "PubChem CID", "url": "http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=57347", "species": "None" }] ligand = Ligand(self.ligand_json) self.assertEqual(len(ligand.database_links()), 2) self.assertIsInstance(ligand.database_links()[0], DatabaseLink) self.assertIsInstance(ligand.database_links()[1], DatabaseLink) self.assertEqual(ligand.database_links()[0].accession(), "CHEMBL1742477") self.assertEqual(ligand.database_links()[1].accession(), "57347")
def test_gtop_pdbs_when_no_json(self, mock_json_retriever): mock_json_retriever.return_value = None ligand = Ligand(self.ligand_json) self.assertEqual(ligand.gtop_pdbs(), [])
def test_interactions_when_no_json(self, mock_json_retriever): mock_json_retriever.return_value = None ligand = Ligand(self.ligand_json) self.assertEqual(ligand.interactions(), [])
def test_can_find_ligand_in_pdb_by_name(self): ligand = Ligand(self.ligand_json) molecule = ligand.find_in_pdb_by_name(self.pdb) self.assertIs(molecule, self.molecule2)
def test_can_find_ligand_in_pdb_by_peptide_string(self, mock_json_retriever): mock_json_retriever.return_value = {"oneLetterSeq": "ABCDEFG"} ligand = Ligand(self.ligand_json) molecule = ligand.find_in_pdb_by_peptide_string(self.pdb) self.assertIs(molecule, self.chain1)
def test_can_get_name_pdbs_when_no_results(self, mock_xml_retriever): mock_xml_retriever.return_value = None ligand = Ligand(self.ligand_json) pdbs = ligand.name_pdbs() self.assertEqual(pdbs, [])
def test_can_get_name_pdbs(self, mock_xml_retriever): mock_xml_retriever.return_value = ["2XG3", "3A1I"] ligand = Ligand(self.ligand_json) pdbs = ligand.name_pdbs() self.assertEqual(pdbs, ["2XG3", "3A1I"])
def test_can_get_inchi_pdbs(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.return_value = {"inchi": "CCC"} mock_xml_retriever.return_value = ["2XG3", "3A1I"] ligand = Ligand(self.ligand_json) pdbs = ligand.inchi_pdbs() self.assertEqual(pdbs, ["2XG3", "3A1I"])
def test_can_find_ligand_in_pdb_by_mass(self, mock_json_retriever): mock_json_retriever.return_value = {"molecularWeight": 100} ligand = Ligand(self.ligand_json) molecule = ligand.find_in_pdb_by_mass(self.pdb) self.assertIs(molecule, self.molecule3)
def test_can_find_ligand_in_pdb_by_smiles(self, mock_json_retriever): mock_json_retriever.return_value = {"smiles": "CCCOOOCOCOCO"} ligand = Ligand(self.ligand_json) molecule = ligand.find_in_pdb_by_smiles(self.pdb) self.assertIs(molecule, self.molecule1)
def test_can_get_interaction_by_id(self, mock_json_retriever): mock_json_retriever.return_value = [self.interaction_json, self.interaction_json] ligand = Ligand(self.ligand_json) interaction = ligand.get_interaction_by_id(self.interaction_json["interactionId"]) self.assertIsInstance(interaction, Interaction)
def test_interaction_id_id_must_be_int(self, mock_json_retriever): mock_json_retriever.return_value =[self.interaction_json, self.interaction_json] ligand = Ligand(self.ligand_json) with self.assertRaises(TypeError): ligand.get_interaction_by_id("1")
def test_cannot_get_interaction_by_invalid_id(self, mock_json_retriever): mock_json_retriever.return_value = None ligand = Ligand(self.ligand_json) with self.assertRaises(exceptions.NoSuchInteractionError): interaction = ligand.get_interaction_by_id(0)