class GuessIonTests(unittest.TestCase): geneSet = genetic.generate_geneset() df = salty.load_data("cationInfo.csv") parent_candidates = df['smiles'].unique() df = salty.load_data("anionInfo.csv") df = df['smiles'].unique() random.seed(1234) ohPickMe = random.sample(range(df.shape[0]), 1) anion = Chem.MolFromSmiles(df[ohPickMe[0]]) def test_1_density(self): target = 1250 self.guess_password(target) def test_benchmark(self): genetic.Benchmark.run(self.test_1_density) def guess_password(self, target): startTime = datetime.datetime.now() def fnGetFitness(genes, target): return get_fitness(self.anion, genes, target) def fnDisplay(candidate, mutation, target): display(candidate, mutation, startTime) def fnShowIon(genes, target, mutation_attempts, sim_score, molecular_relative): show_ion(genes, target, mutation_attempts, sim_score, molecular_relative, self.anion) optimalFitness = 0.9 best = genetic.get_best(fnGetFitness, optimalFitness, self.geneSet, fnDisplay, fnShowIon, target, self.parent_candidates, seed=123) cation = best.Mol anion = self.anion # Uncomment PDB lines to wrote PDB file # cation = Chem.AddHs(best.Mol) # Chem.EmbedMolecule(cation, Chem.ETKDG()) # Chem.UFFOptimizeMolecule(cation) # Chem.rdmolfiles.MolToPDBFile(cation, "cation_test.pdb") # anion = Chem.AddHs(self.anion) # Chem.EmbedMolecule(anion, Chem.ETKDG()) # Chem.UFFOptimizeMolecule(anion) # Chem.rdmolfiles.MolToPDBFile(anion, "anion_test.pdb") return cation, anion
class iupac_smiles_tests(unittest.TestCase): data_files = ["cationInfo.csv", "anionInfo.csv"] df = salty.load_data(data_files[0]) smiles = df.smiles for i in range(len(smiles)): ion = smiles[i] salty.check_name(ion) def test_1_check_data(self): for i in range(len(self.data_files)): df = salty.load_data(self.data_files[i]) self.check_data(df) def test_2_check_wrong_ion(selfs): ion = 'stupid_nonsense_string' salty.check_name(ion) def test_benchmark(self): salty.Benchmark.run(self.test_1_check_data) salty.Benchmark.run(self.test_2_check_wrong_ion) def check_data(self, df): startTime = datetime.datetime.now() def fnDisplay(message): display(message, startTime) smiles = df.smiles for i in range(len(smiles)): ion = smiles[i] try: Chem.SanitizeMol(Chem.MolFromSmiles(ion)) except ValueError: name = salty.check_name(ion) message = "RDKit cannot interpret %s ion SMILES in datafile" \ % name fnDisplay(message) if "-" not in ion and "+" not in ion: name = salty.check_name(ion) message = "%s ion does not have a charge" % name fnDisplay(message) if "." in ion: name = salty.check_name(ion) message = "%s ion contains more than one molecular entity" \ % name fnDisplay(message)
def test_1_check_data(self): for i in range(len(self.data_files)): df = salty.load_data(self.data_files[i]) self.check_data(df)
class GuessIonTests(unittest.TestCase): geneSet = genetic.generate_geneset() df = salty.load_data("cationInfo.csv") df = df.loc[df["name"].str.contains("imid", case=False)]