-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Milestone
Description
Hi folks,
First of all, thank you very much for all your work. It's really interesting. I have tried to use XenonPy and try to rebuild your tutorial. Unfortunately, I observed 2 errors by using the following codes:
Package version: 0.5.1
NGram issue with unkown ngram_tab
I think it was replace by ngram_table
, but I'm not sure.
# N-gram library in XenonPy-iQSPR
from xenonpy.inverse.iqspr import NGram
# initialize a new n-gram
n_gram = NGram()
#n_gram.ngram_tab = n_gram.ngram_table
# train the n-gram with SMILES of available molecules
n_gram.fit(data_ss['SMILES'],train_order=5)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
968
969 if method is not None:
--> 970 return method(include=include, exclude=exclude)
971 return None
972 else:
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/base.py in _repr_mimebundle_(self, **kwargs)
462 def _repr_mimebundle_(self, **kwargs):
463 """Mime bundle used by jupyter kernels to display estimator"""
--> 464 output = {"text/plain": repr(self)}
465 if get_config()["display"] == 'diagram':
466 output["text/html"] = estimator_html_repr(self)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/base.py in __repr__(self, N_CHAR_MAX)
258 n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)
259
--> 260 repr_ = pp.pformat(self)
261
262 # Use bruteforce ellipsis when there are a lot of non-blank characters
~/anaconda/envs/xenonpy/lib/python3.7/pprint.py in pformat(self, object)
142 def pformat(self, object):
143 sio = _StringIO()
--> 144 self._format(object, sio, 0, 0, {}, 0)
145 return sio.getvalue()
146
~/anaconda/envs/xenonpy/lib/python3.7/pprint.py in _format(self, object, stream, indent, allowance, context, level)
159 self._readable = False
160 return
--> 161 rep = self._repr(object, context, level)
162 max_width = self._width - indent - allowance
163 if len(rep) > max_width:
~/anaconda/envs/xenonpy/lib/python3.7/pprint.py in _repr(self, object, context, level)
391 def _repr(self, object, context, level):
392 repr, readable, recursive = self.format(object, context.copy(),
--> 393 self._depth, level)
394 if not readable:
395 self._readable = False
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/utils/_pprint.py in format(self, object, context, maxlevels, level)
179 def format(self, object, context, maxlevels, level):
180 return _safe_repr(object, context, maxlevels, level,
--> 181 changed_only=self._changed_only)
182
183 def _pprint_estimator(self, object, stream, indent, allowance, context,
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/utils/_pprint.py in _safe_repr(object, context, maxlevels, level, changed_only)
423 recursive = False
424 if changed_only:
--> 425 params = _changed_params(object)
426 else:
427 params = object.get_params(deep=False)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/utils/_pprint.py in _changed_params(estimator)
89 estimator with non-default values."""
90
---> 91 params = estimator.get_params(deep=False)
92 init_func = getattr(estimator.__init__, 'deprecated_original',
93 estimator.__init__)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/base.py in get_params(self, deep)
193 out = dict()
194 for key in self._get_param_names():
--> 195 value = getattr(self, key)
196 if deep and hasattr(value, 'get_params'):
197 deep_items = value.get_params().items()
AttributeError: 'NGram' object has no attribute 'ngram_tab'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
700 type_pprinters=self.type_printers,
701 deferred_pprinters=self.deferred_printers)
--> 702 printer.pretty(obj)
703 printer.flush()
704 return stream.getvalue()
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
392 if cls is not object \
393 and callable(cls.__dict__.get('__repr__')):
--> 394 return _repr_pprint(obj, self, cycle)
395
396 return _default_pprint(obj, self, cycle)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
698 """A pprint that just redirects to the normal repr function."""
699 # Find newlines and replace them with p.break_()
--> 700 output = repr(obj)
701 lines = output.splitlines()
702 with p.group():
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/base.py in __repr__(self, N_CHAR_MAX)
258 n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)
259
--> 260 repr_ = pp.pformat(self)
261
262 # Use bruteforce ellipsis when there are a lot of non-blank characters
~/anaconda/envs/xenonpy/lib/python3.7/pprint.py in pformat(self, object)
142 def pformat(self, object):
143 sio = _StringIO()
--> 144 self._format(object, sio, 0, 0, {}, 0)
145 return sio.getvalue()
146
~/anaconda/envs/xenonpy/lib/python3.7/pprint.py in _format(self, object, stream, indent, allowance, context, level)
159 self._readable = False
160 return
--> 161 rep = self._repr(object, context, level)
162 max_width = self._width - indent - allowance
163 if len(rep) > max_width:
~/anaconda/envs/xenonpy/lib/python3.7/pprint.py in _repr(self, object, context, level)
391 def _repr(self, object, context, level):
392 repr, readable, recursive = self.format(object, context.copy(),
--> 393 self._depth, level)
394 if not readable:
395 self._readable = False
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/utils/_pprint.py in format(self, object, context, maxlevels, level)
179 def format(self, object, context, maxlevels, level):
180 return _safe_repr(object, context, maxlevels, level,
--> 181 changed_only=self._changed_only)
182
183 def _pprint_estimator(self, object, stream, indent, allowance, context,
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/utils/_pprint.py in _safe_repr(object, context, maxlevels, level, changed_only)
423 recursive = False
424 if changed_only:
--> 425 params = _changed_params(object)
426 else:
427 params = object.get_params(deep=False)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/utils/_pprint.py in _changed_params(estimator)
89 estimator with non-default values."""
90
---> 91 params = estimator.get_params(deep=False)
92 init_func = getattr(estimator.__init__, 'deprecated_original',
93 estimator.__init__)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/sklearn/base.py in get_params(self, deep)
193 out = dict()
194 for key in self._get_param_names():
--> 195 value = getattr(self, key)
196 if deep and hasattr(value, 'get_params'):
197 deep_items = value.get_params().items()
AttributeError: 'NGram' object has no attribute 'ngram_tab'
Unkown error in iQSPR
import pickle as pk
# library for running iQSPR in XenonPy-iQSPR
from xenonpy.inverse.iqspr import IQSPR
# update NGram parameters for this exampleHOMO-LUMO gap
n_gram.set_params(del_range=[1,20],max_len=500, reorder_prob=0.5, sample_order=(1,20))
n_gram.ngram_tab = n_gram.ngram_table
# set up likelihood and n-gram models in iQSPR
iqspr_reorder = IQSPR(estimator=prd_mdls, modifier=n_gram)
np.random.seed(201906) # fix the random seed
# main loop of iQSPR
iqspr_samples1, iqspr_loglike1, iqspr_prob1, iqspr_freq1 = [], [], [], []
for s, ll, p, freq in iqspr_reorder(init_samples, beta, yield_lpf=True):
iqspr_samples1.append(s)
iqspr_loglike1.append(ll)
iqspr_prob1.append(p)
iqspr_freq1.append(freq)
# record all outputs
iqspr_results_reorder = {
"samples": iqspr_samples1,
"loglike": iqspr_loglike1,
"prob": iqspr_prob1,
"freq": iqspr_freq1,
"beta": beta
}
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-82-baffb74333e7> in <module>
----> 1 list(iqspr_reorder(init_samples, beta, yield_lpf=True))
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/inverse/base.py in __call__(self, samples, beta, size, yield_lpf)
520 self.on_errors(i + 1, samples, e)
521 except Exception as e:
--> 522 raise e
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/inverse/base.py in __call__(self, samples, beta, size, yield_lpf)
503 try:
504 re_samples = self.resample(unique, frequency, size, p)
--> 505 samples = self.proposal(re_samples)
506
507 unique, frequency = self.unique(samples)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/utils/useful_cls.py in fn_(self, *args, **kwargs)
100 self._timer.start(fn.__name__)
101 try:
--> 102 rt = fn(self, *args, **kwargs)
103 finally:
104 self._timer.stop(fn.__name__)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/inverse/base.py in proposal(self, X)
395 raise NotImplementedError('user need to implement <proposal> method or'
396 'set <self._proposal> to a instance of <BaseProposal>')
--> 397 return self._proposal(X)
398
399 def on_errors(self, ite, samples, error):
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/inverse/base.py in __call__(self, X)
283
284 def __call__(self, X):
--> 285 return self.proposal(X)
286
287 def on_errors(self, error):
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/utils/useful_cls.py in fn_(self, *args, **kwargs)
100 self._timer.start(fn.__name__)
101 try:
--> 102 rt = fn(self, *args, **kwargs)
103 finally:
104 self._timer.stop(fn.__name__)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/inverse/iqspr/modifier.py in proposal(self, smiles)
578
579 except Exception as e:
--> 580 raise e
581
582 return new_smis
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/inverse/iqspr/modifier.py in proposal(self, smiles)
565 ext_smi = self.smi2esmi(smi)
566 try:
--> 567 new_ext_smi = self.modify(ext_smi)
568 new_smi = self.esmi2smi(new_ext_smi)
569 if Chem.MolFromSmiles(new_smi) is None:
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/utils/useful_cls.py in fn_(self, *args, **kwargs)
100 self._timer.start(fn.__name__)
101 try:
--> 102 rt = fn(self, *args, **kwargs)
103 finally:
104 self._timer.stop(fn.__name__)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/inverse/iqspr/modifier.py in modify(self, ext_smi)
206 # add until reaching '!' or a given max value
207 for i in range(self.max_len - len(ext_smi)):
--> 208 ext_smi, _ = self.sample_next_char(ext_smi)
209 if ext_smi['esmi'].iloc[-1] == '!':
210 return ext_smi # stop when hitting '!', assume must be valid SMILES
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/utils/useful_cls.py in fn_(self, *args, **kwargs)
100 self._timer.start(fn.__name__)
101 try:
--> 102 rt = fn(self, *args, **kwargs)
103 finally:
104 self._timer.stop(fn.__name__)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/inverse/iqspr/modifier.py in sample_next_char(self, ext_smi)
447 iB = ext_smi['n_br'].iloc[-1] > 0
448 iR = ext_smi['n_ring'].iloc[-1]
--> 449 cand_char, cand_prob = self.get_prob(ext_smi['substr'].iloc[-1], iB, iR)
450 # here we assume cand_char is not empty
451 idx = np.random.choice(range(len(cand_char)), p=cand_prob)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/utils/useful_cls.py in fn_(self, *args, **kwargs)
100 self._timer.start(fn.__name__)
101 try:
--> 102 rt = fn(self, *args, **kwargs)
103 finally:
104 self._timer.stop(fn.__name__)
~/anaconda/envs/xenonpy/lib/python3.7/site-packages/xenonpy/inverse/iqspr/modifier.py in get_prob(self, tmp_str, iB, iR)
434 for iO in range(self.sample_order[1] - 1, self.sample_order[0] - 2, -1):
435 # if (len(tmp_str) > iO) & (str(tmp_str[-(iO + 1):]) in self._table[iO][iB][iR].index.tolist()):
--> 436 if len(tmp_str) > iO and str(tmp_str[-(iO + 1):]) in self._table[iO][iB][iR].index.tolist():
437 cand_char = self._table[iO][iB][iR].columns.tolist()
438 cand_prob = np.array(self._table[iO][iB][iR].loc[str(tmp_str[-(iO + 1):])])
IndexError: list index out of range```
Metadata
Metadata
Labels
No labels