saicharan2804 commited on
Commit
d3fd51f
·
1 Parent(s): 82e9a5c

Fixed error

Browse files
Files changed (2) hide show
  1. molgenevalmetric.py +26 -24
  2. requirements.txt +1 -0
molgenevalmetric.py CHANGED
@@ -3,8 +3,8 @@ import datasets
3
  # import moses
4
  # from moses import metrics
5
  import pandas as pd
6
- # from tdc import Evaluator
7
- # from tdc import Oracle
8
  # from metrics import novelty, fraction_valid, fraction_unique, SAscore, internal_diversity,fcd_metric, SYBAscore, oracles
9
 
10
  import os
@@ -314,34 +314,34 @@ def fcd_metric(gen, train, n_jobs = 8, device = 'cuda:0'):
314
  # else:
315
  # return None # Or handle empty list or all failed predictions as needed
316
 
317
- # def oracles(gen, train):
318
- # Result = {}
319
- # # evaluator = Evaluator(name = 'KL_Divergence')
320
- # # KL_Divergence = evaluator(gen, train)
321
 
322
- # # Result["KL_Divergence"]: KL_Divergence
323
 
324
 
325
- # oracle_list = [
326
- # 'QED', 'SA', 'MPO', 'GSK3B', 'JNK3',
327
- # 'DRD2', 'LogP', 'Rediscovery', 'Similarity',
328
- # 'Median', 'Isomers', 'Valsartan_SMARTS', 'Hop'
329
- # ]
330
 
331
- # for oracle_name in oracle_list:
332
- # oracle = Oracle(name=oracle_name)
333
- # if oracle_name in ['Rediscovery', 'MPO', 'Similarity', 'Median', 'Isomers', 'Hop']:
334
- # score = oracle(gen)
335
- # if isinstance(score, dict):
336
- # score = {key: sum(values)/len(values) for key, values in score.items()}
337
- # else:
338
- # score = oracle(gen)
339
- # if isinstance(score, list):
340
- # score = sum(score) / len(score)
341
 
342
- # Result[f"{oracle_name}"] = score
343
 
344
- # return Result
345
 
346
 
347
 
@@ -423,6 +423,8 @@ class molgenevalmetric(evaluate.Metric):
423
  metrics['unique'] = fraction_unique(gen=gensmi)
424
  metrics['IntDiv'] = internal_diversity(gen=gensmi)
425
  metrics['FCD'] = fcd_metric(gen = gensmi, train = trainsmi)
 
 
426
  # metrics['SA'] = SAscore(gen=gensmi)
427
  # metrics['SCS'] = SAscore(gen=trainsmi)
428
 
 
3
  # import moses
4
  # from moses import metrics
5
  import pandas as pd
6
+ from tdc import Evaluator
7
+ from tdc import Oracle
8
  # from metrics import novelty, fraction_valid, fraction_unique, SAscore, internal_diversity,fcd_metric, SYBAscore, oracles
9
 
10
  import os
 
314
  # else:
315
  # return None # Or handle empty list or all failed predictions as needed
316
 
317
+ def oracles(gen, train):
318
+ Result = {}
319
+ # evaluator = Evaluator(name = 'KL_Divergence')
320
+ # KL_Divergence = evaluator(gen, train)
321
 
322
+ # Result["KL_Divergence"]: KL_Divergence
323
 
324
 
325
+ oracle_list = [
326
+ 'QED', 'SA', 'MPO', 'GSK3B', 'JNK3',
327
+ 'DRD2', 'LogP', 'Rediscovery', 'Similarity',
328
+ 'Median', 'Isomers', 'Valsartan_SMARTS', 'Hop'
329
+ ]
330
 
331
+ for oracle_name in oracle_list:
332
+ oracle = Oracle(name=oracle_name)
333
+ if oracle_name in ['Rediscovery', 'MPO', 'Similarity', 'Median', 'Isomers', 'Hop']:
334
+ score = oracle(gen)
335
+ if isinstance(score, dict):
336
+ score = {key: sum(values)/len(values) for key, values in score.items()}
337
+ else:
338
+ score = oracle(gen)
339
+ if isinstance(score, list):
340
+ score = sum(score) / len(score)
341
 
342
+ Result[f"{oracle_name}"] = score
343
 
344
+ return Result
345
 
346
 
347
 
 
423
  metrics['unique'] = fraction_unique(gen=gensmi)
424
  metrics['IntDiv'] = internal_diversity(gen=gensmi)
425
  metrics['FCD'] = fcd_metric(gen = gensmi, train = trainsmi)
426
+ metrics['Oracles'] = oracles(gen = gensmi, train = trainsmi)
427
+
428
  # metrics['SA'] = SAscore(gen=gensmi)
429
  # metrics['SCS'] = SAscore(gen=trainsmi)
430
 
requirements.txt CHANGED
@@ -7,3 +7,4 @@ torch
7
  rdkit
8
  pyarrow
9
  fcd-torch
 
 
7
  rdkit
8
  pyarrow
9
  fcd-torch
10
+ PyTDC