<commit_before>import unittest
import sys
sys.path.append(".")
sys.path.append("..")
import pygtop


class LigandAccess(unittest.TestCase):
    """This is the test for version 0.1.

    In this version, the user can access a ligand by ID, and access most of the
    properties accessible from the API. They cannot currently access interaction,
     PDB, rank order, complex, subunit or image information.

    They can also use the API ligand searcher for basic attributes, but not
    SMILES queries. This is extended to allow for getting a ligand by name."""

    def check_ligand_basic_properties(self, ligand):
        self.assertIsInstance(ligand, pygtop.Ligand)
        self.assertIsInstance(ligand.name, str)
        self.assertIsInstance(ligand.abbreviation, str)
        self.assertIsInstance(ligand.inn, str)
        if ligand.species: self.assertIsInstance(ligand.species, str)
        self.assertIsInstance(ligand.type, str)
        self.assertIsInstance(ligand.radioactive, bool)
        self.assertIsInstance(ligand.labelled, bool)
        self.assertIsInstance(ligand.approved, bool)
        self.assertIsInstance(ligand.withdrawn, bool)
        self.assertIsInstance(ligand.approval_source, str)
        self.assertIsInstance(ligand.subunit_ids, list)
        if ligand.subunit_ids: self.assertIsInstance(ligand.subunit_ids[0], int)
        self.assertIsInstance(ligand.complex_ids, list)
        if ligand.complex_ids: self.assertIsInstance(ligand.complex_ids[0], int)
        self.assertIsInstance(ligand.prodrug_ids, list)
        if ligand.prodrug_ids: self.assertIsInstance(ligand.prodrug_ids[0], int)
        self.assertIsInstance(ligand.active_drug_ids, list)
        if ligand.active_drug_ids: self.assertIsInstance(ligand.active_drug_ids[0], int)


    def check_ligand_structural_properties(self, ligand):
        if ligand.iupac_name:
            self.assertIsInstance(ligand.iupac_name, str)
        if ligand.smiles:
            self.assertIsInstance(ligand.smiles, str)
        if ligand.inchi:
            self.assertIsInstance(ligand.inchi, str)
        if ligand.inchi_key:
            self.assertIsInstance(ligand.inchi_key, str)
        if ligand.one_letter_sequence:
            self.assertIsInstance(ligand.one_letter_sequence, str)
        if ligand.three_letter_sequence:
            self.assertIsInstance(ligand.three_letter_sequence, str)
        if ligand.post_translational_modifications:
            self.assertIsInstance(ligand.post_translational_modifications, str)
        if ligand.chemical_modifications:
            self.assertIsInstance(ligand.chemical_modifications, str)


    def check_ligand_molecular_properties(self, ligand):
        self.assertIsInstance(ligand.hydrogen_bond_acceptors, int)
        self.assertIsInstance(ligand.hydrogen_bond_donors, int)
        self.assertIsInstance(ligand.rotatable_bonds, int)
        self.assertIsInstance(ligand.topological_polar_surface_area, float)
        self.assertIsInstance(ligand.molecular_weight, float)
        self.assertIsInstance(ligand.log_p, float)
        self.assertIsInstance(ligand.lipinksi_rules_broken, int)


    def check_ligand_database_properties(self, ligand):
        self.assertIsInstance(ligand.database_links, list)
        for link in ligand.database_links():
            self.assertIsInstance(link, pygtop.DatabaseLink)
            if link.accession: self.assertIsInstance(link.accession, str)
            if link.database: self.assertIsInstance(link.database, str)
            if link.url: self.assertIsInstance(link.url, str)
            if link.species: self.assertIsInstance(link.species, str)


    def check_ligand_synonym_properties(self, ligand):
        self.assertIsInstance(ligand.synonyms, list)
        for synonym in ligand.synonyms:
            self.assertIsInstance(synonym, str)
            self.assertGreater(len(synonym), 0)


    def check_ligand_comment_properties(self, ligand):
        self.assertIsInstance(ligand.general_comments, str)
        self.assertIsInstance(ligand.bioactivity_comments, str)
        self.assertIsInstance(ligand.clinical_use_comments, str)
        self.assertIsInstance(ligand.mechanism_of_action_comments, str)
        self.assertIsInstance(ligand.absorption_and_distribution_comments, str)
        self.assertIsInstance(ligand.metabolism_comments, str)
        self.assertIsInstance(ligand.elimination_comments, str)
        self.assertIsInstance(ligand.population_pharmacokinetics_comments, str)
        self.assertIsInstance(ligand.organ_function_impairments_comments, str)
        self.assertIsInstance(ligand.mutations_and_pathophysiology_comments, str)


    def check_ligand_precursor_properties(self, ligand):
        self.assertIsInstance(ligand.precursors, list)
        for precursor in ligand.precursors:
            self.assertIsInstance(precursor, pygtop.Precursor)
            self.assertIsInstance(precursor.precursor_id, int)
            self.assertIsInstance(precursor.gene_symbol, str)
            self.assertIsInstance(precursor.gene_name)
            self.assertIsInstance(precursor.official_gene_id, str)
            self.assertIsInstance(precursor.protein_name, str)
            self.assertIsInstance(precursor.species, str)
            self.assertIsInstance(precursor.synonyms, list)
            for synonym in precursor.synonyms:
                self.assertIsInstance(synonym, str)
                self.assertGreater(len(synonym), 0)


    def check_ligand_complete(self, ligand):
        self.check_ligand_basic_properties()
        ligand.get_all_properties()
        self.check_ligand_structural_properties(ligand)
        self.check_ligand_molecular_properties(ligand)
        self.check_ligand_database_properties(ligand)
        self.check_ligand_synonym_properties(ligand)
        self.check_ligand_comment_properties(ligand)
        self.check_ligand_precursor_properties(ligand)



    def test_can_get_single_ligand(self):
        # The user gets a ligand by ID
        ligand = pygtop.get_ligand_by_id(1)

        # The user checks its basic properties
        self.check_ligand_basic_properties(ligand)

        # The user tries to get a ligand with a false ID
        self.assertRaises(pygtop.get_ligand_id(1000000000), pygtop.NoSuchLigandError)

        # The user decides to get the structural information for the ligand
        ligand.get_structural_properties()
        self.check_ligand_structural_properties(ligand)
        self.check_ligand_basic_properties()
        self.check_ligand_molecular_properties(ligand)

        # The user decides to get database properties for the ligand
        ligand.get_database_properties()
        self.check_ligand_database_properties(ligand)

        # The user decides to get synonym properties for the ligand
        ligand.get_synonym_properties()
        self.check_ligand_synonym_properties(ligand)

        # The user decides to get comment properties for the ligand
        ligand.get_comment_properties()
        self.check_ligand_comment_properties(ligand)

        # The user decides to get precursor properties for the ligand
        ligand.get_precursor_properties()
        self.check_ligand_precursor_properties(ligand)

        # The user gets a random ligand<commit_msg>Make further fix to 0.1 functional test<commit_after>import unittest
import sys
sys.path.append(".")
sys.path.append("..")
import pygtop


class LigandAccess(unittest.TestCase):
    """This is the test for version 0.1.

    In this version, the user can access a ligand by ID, and access most of the
    properties accessible from the API. They cannot currently access interaction,
     PDB, rank order, complex, subunit or image information.

    They can also use the API ligand searcher for basic attributes, but not
    SMILES queries. This is extended to allow for getting a ligand by name."""

    def check_ligand_basic_properties(self, ligand):
        self.assertIsInstance(ligand, pygtop.Ligand)
        self.assertIsInstance(ligand.name, str)
        self.assertIsInstance(ligand.abbreviation, str)
        self.assertIsInstance(ligand.inn, str)
        if ligand.species: self.assertIsInstance(ligand.species, str)
        self.assertIsInstance(ligand.type, str)
        self.assertIsInstance(ligand.radioactive, bool)
        self.assertIsInstance(ligand.labelled, bool)
        self.assertIsInstance(ligand.approved, bool)
        self.assertIsInstance(ligand.withdrawn, bool)
        self.assertIsInstance(ligand.approval_source, str)
        self.assertIsInstance(ligand.subunit_ids, list)
        if ligand.subunit_ids: self.assertIsInstance(ligand.subunit_ids[0], int)
        self.assertIsInstance(ligand.complex_ids, list)
        if ligand.complex_ids: self.assertIsInstance(ligand.complex_ids[0], int)
        self.assertIsInstance(ligand.prodrug_ids, list)
        if ligand.prodrug_ids: self.assertIsInstance(ligand.prodrug_ids[0], int)
        self.assertIsInstance(ligand.active_drug_ids, list)
        if ligand.active_drug_ids: self.assertIsInstance(ligand.active_drug_ids[0], int)


    def check_ligand_structural_properties(self, ligand):
        if ligand.iupac_name:
            self.assertIsInstance(ligand.iupac_name, str)
        if ligand.smiles:
            self.assertIsInstance(ligand.smiles, str)
        if ligand.inchi:
            self.assertIsInstance(ligand.inchi, str)
        if ligand.inchi_key:
            self.assertIsInstance(ligand.inchi_key, str)
        if ligand.one_letter_sequence:
            self.assertIsInstance(ligand.one_letter_sequence, str)
        if ligand.three_letter_sequence:
            self.assertIsInstance(ligand.three_letter_sequence, str)
        if ligand.post_translational_modifications:
            self.assertIsInstance(ligand.post_translational_modifications, str)
        if ligand.chemical_modifications:
            self.assertIsInstance(ligand.chemical_modifications, str)


    def check_ligand_molecular_properties(self, ligand):
        self.assertIsInstance(ligand.hydrogen_bond_acceptors, int)
        self.assertIsInstance(ligand.hydrogen_bond_donors, int)
        self.assertIsInstance(ligand.rotatable_bonds, int)
        self.assertIsInstance(ligand.topological_polar_surface_area, float)
        self.assertIsInstance(ligand.molecular_weight, float)
        self.assertIsInstance(ligand.log_p, float)
        self.assertIsInstance(ligand.lipinksi_rules_broken, int)


    def check_ligand_database_properties(self, ligand):
        self.assertIsInstance(ligand.database_links, list)
        for link in ligand.database_links():
            self.assertIsInstance(link, pygtop.DatabaseLink)
            if link.accession: self.assertIsInstance(link.accession, str)
            if link.database: self.assertIsInstance(link.database, str)
            if link.url: self.assertIsInstance(link.url, str)
            if link.species: self.assertIsInstance(link.species, str)


    def check_ligand_synonym_properties(self, ligand):
        self.assertIsInstance(ligand.synonyms, list)
        for synonym in ligand.synonyms:
            self.assertIsInstance(synonym, str)
            self.assertGreater(len(synonym), 0)


    def check_ligand_comment_properties(self, ligand):
        self.assertIsInstance(ligand.general_comments, str)
        self.assertIsInstance(ligand.bioactivity_comments, str)
        self.assertIsInstance(ligand.clinical_use_comments, str)
        self.assertIsInstance(ligand.mechanism_of_action_comments, str)
        self.assertIsInstance(ligand.absorption_and_distribution_comments, str)
        self.assertIsInstance(ligand.metabolism_comments, str)
        self.assertIsInstance(ligand.elimination_comments, str)
        self.assertIsInstance(ligand.population_pharmacokinetics_comments, str)
        self.assertIsInstance(ligand.organ_function_impairments_comments, str)
        self.assertIsInstance(ligand.mutations_and_pathophysiology_comments, str)


    def check_ligand_precursor_properties(self, ligand):
        self.assertIsInstance(ligand.precursors, list)
        for precursor in ligand.precursors:
            self.assertIsInstance(precursor, pygtop.Precursor)
            self.assertIsInstance(precursor.precursor_id, int)
            self.assertIsInstance(precursor.gene_symbol, str)
            self.assertIsInstance(precursor.gene_name)
            self.assertIsInstance(precursor.official_gene_id, str)
            self.assertIsInstance(precursor.protein_name, str)
            self.assertIsInstance(precursor.species, str)
            self.assertIsInstance(precursor.synonyms, list)
            for synonym in precursor.synonyms:
                self.assertIsInstance(synonym, str)
                self.assertGreater(len(synonym), 0)


    def check_ligand_complete(self, ligand):
        self.check_ligand_basic_properties()
        ligand.get_all_properties()
        self.check_ligand_structural_properties(ligand)
        self.check_ligand_molecular_properties(ligand)
        self.check_ligand_database_properties(ligand)
        self.check_ligand_synonym_properties(ligand)
        self.check_ligand_comment_properties(ligand)
        self.check_ligand_precursor_properties(ligand)


    def test_can_get_single_ligand(self):
        # The user gets a ligand by ID
        ligand = pygtop.get_ligand_by_id(1)

        # The user checks its basic properties
        self.check_ligand_basic_properties(ligand)

        # The user tries to get a ligand with a false ID
        self.assertRaises(pygtop.get_ligand_id(1000000000), pygtop.NoSuchLigandError)

        # The user decides to get the structural information for the ligand
        ligand.get_structural_properties()
        self.check_ligand_structural_properties(ligand)

        # The user tries to access molecular properties
        self.assertRaises(ligand.rotatable_bonds, pygtop.PropertyNotRequestedYetError)

        # The user decides to get molecular properties for the ligand
        ligand.get_molecular_properties()
        self.check_ligand_molecular_properties(ligand)

        # The user decides to get database properties for the ligand
        ligand.get_database_properties()
        self.check_ligand_database_properties(ligand)

        # The user decides to get synonym properties for the ligand
        ligand.get_synonym_properties()
        self.check_ligand_synonym_properties(ligand)

        # The user decides to get comment properties for the ligand
        ligand.get_comment_properties()
        self.check_ligand_comment_properties(ligand)

        # The user decides to get precursor properties for the ligand
        ligand.get_precursor_properties()
        self.check_ligand_precursor_properties(ligand)

        # The user gets a random ligand
{'fraction_non_alphanumeric': 0.07267422134762842, 'fraction_numerical': 0.002714256632964647, 'mean_word_length': 3.400716631830397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6855854', 'n_tokens_mistral': 4480, 'n_tokens_neox': 4203, 'n_words': 798}