cnotebook 2.1.0__py3-none-any.whl → 2.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cnotebook/__init__.py CHANGED
@@ -13,7 +13,7 @@ from openeye import oechem, oedepict
13
13
  from .context import cnotebook_context, CNotebookContext
14
14
  from .helpers import highlight_smarts
15
15
 
16
- __version__ = '2.1.0'
16
+ __version__ = '2.1.2'
17
17
 
18
18
  # Configure logging first
19
19
  log = logging.getLogger("cnotebook")
@@ -7,7 +7,7 @@ from typing import Iterable, List, Optional, Union
7
7
  def molgrid(
8
8
  mols: Iterable,
9
9
  *,
10
- title_field: Optional[str] = "Title",
10
+ title: Union[bool, str, None] = True,
11
11
  tooltip_fields: Optional[List[str]] = None,
12
12
  n_items_per_page: int = 24,
13
13
  width: int = 200,
@@ -22,7 +22,8 @@ def molgrid(
22
22
  """Create an interactive molecule grid.
23
23
 
24
24
  :param mols: Iterable of OpenEye molecule objects.
25
- :param title_field: Molecule field for title (None to hide).
25
+ :param title: Title display mode. True uses molecule's title, a string
26
+ specifies a field name, None/False hides titles.
26
27
  :param tooltip_fields: List of fields for tooltip.
27
28
  :param n_items_per_page: Molecules per page.
28
29
  :param width: Image width in pixels (default 200).
@@ -38,7 +39,7 @@ def molgrid(
38
39
  """
39
40
  return MolGrid(
40
41
  mols,
41
- title_field=title_field,
42
+ title=title,
42
43
  tooltip_fields=tooltip_fields,
43
44
  n_items_per_page=n_items_per_page,
44
45
  width=width,
cnotebook/grid/grid.py CHANGED
@@ -615,7 +615,7 @@ class MolGrid:
615
615
  *,
616
616
  dataframe=None,
617
617
  mol_col: Optional[str] = None,
618
- title_field: Optional[str] = "Title",
618
+ title: Union[bool, str, None] = True,
619
619
  tooltip_fields: Optional[List[str]] = None,
620
620
  n_items_per_page: int = 24,
621
621
  width: int = 200,
@@ -633,7 +633,8 @@ class MolGrid:
633
633
  :param mols: Iterable of OpenEye molecule objects.
634
634
  :param dataframe: Optional DataFrame with molecule data.
635
635
  :param mol_col: Column name containing molecules (if using DataFrame).
636
- :param title_field: Molecule field to display as title (None to hide).
636
+ :param title: Title display mode. True uses molecule's title, a string
637
+ specifies a field name, None/False hides titles.
637
638
  :param tooltip_fields: List of fields for tooltip display.
638
639
  :param n_items_per_page: Number of molecules per page.
639
640
  :param width: Image width in pixels.
@@ -650,7 +651,7 @@ class MolGrid:
650
651
  self._molecules = list(mols)
651
652
  self._dataframe = dataframe
652
653
  self._mol_col = mol_col
653
- self.title_field = title_field
654
+ self.title = title if title else None
654
655
  self.tooltip_fields = tooltip_fields or []
655
656
  self.n_items_per_page = n_items_per_page
656
657
  self.selection_enabled = select
@@ -860,6 +861,7 @@ class MolGrid:
860
861
  height=self.height,
861
862
  image_format=self.image_format,
862
863
  atom_label_font_scale=self.atom_label_font_scale,
864
+ title=False,
863
865
  scope="local",
864
866
  )
865
867
 
@@ -874,8 +876,12 @@ class MolGrid:
874
876
  }
875
877
 
876
878
  # Extract title
877
- if self.title_field:
878
- item["title"] = self._get_field_value(idx, mol, self.title_field)
879
+ if self.title is True:
880
+ # Use molecule's built-in title
881
+ item["title"] = mol.GetTitle() if mol.IsValid() else None
882
+ elif self.title:
883
+ # Use specified field name
884
+ item["title"] = self._get_field_value(idx, mol, self.title)
879
885
 
880
886
  # Extract tooltip fields
881
887
  for field in self.tooltip_fields:
@@ -0,0 +1,2 @@
1
+ var List;List=function(){var t={"./src/add-async.js":function(t){t.exports=function(t){return function e(r,n,s){var i=r.splice(0,50);s=(s=s||[]).concat(t.add(i)),r.length>0?setTimeout((function(){e(r,n,s)}),1):(t.update(),n(s))}}},"./src/filter.js":function(t){t.exports=function(t){return t.handlers.filterStart=t.handlers.filterStart||[],t.handlers.filterComplete=t.handlers.filterComplete||[],function(e){if(t.trigger("filterStart"),t.i=1,t.reset.filter(),void 0===e)t.filtered=!1;else{t.filtered=!0;for(var r=t.items,n=0,s=r.length;n<s;n++){var i=r[n];e(i)?i.filtered=!0:i.filtered=!1}}return t.update(),t.trigger("filterComplete"),t.visibleItems}}},"./src/fuzzy-search.js":function(t,e,r){r("./src/utils/classes.js");var n=r("./src/utils/events.js"),s=r("./src/utils/extend.js"),i=r("./src/utils/to-string.js"),a=r("./src/utils/get-by-class.js"),o=r("./src/utils/fuzzy.js");t.exports=function(t,e){e=s({location:0,distance:100,threshold:.4,multiSearch:!0,searchClass:"fuzzy-search"},e=e||{});var r={search:function(n,s){for(var i=e.multiSearch?n.replace(/ +$/,"").split(/ +/):[n],a=0,o=t.items.length;a<o;a++)r.item(t.items[a],s,i)},item:function(t,e,n){for(var s=!0,i=0;i<n.length;i++){for(var a=!1,o=0,l=e.length;o<l;o++)r.values(t.values(),e[o],n[i])&&(a=!0);a||(s=!1)}t.found=s},values:function(t,r,n){if(t.hasOwnProperty(r)){var s=i(t[r]).toLowerCase();if(o(s,n,e))return!0}return!1}};return n.bind(a(t.listContainer,e.searchClass),"keyup",t.utils.events.debounce((function(e){var n=e.target||e.srcElement;t.search(n.value,r.search)}),t.searchDelay)),function(e,n){t.search(e,n,r.search)}}},"./src/index.js":function(t,e,r){var n=r("./node_modules/string-natural-compare/natural-compare.js"),s=r("./src/utils/get-by-class.js"),i=r("./src/utils/extend.js"),a=r("./src/utils/index-of.js"),o=r("./src/utils/events.js"),l=r("./src/utils/to-string.js"),u=r("./src/utils/classes.js"),c=r("./src/utils/get-attribute.js"),f=r("./src/utils/to-array.js");t.exports=function(t,e,h){var d,v=this,g=r("./src/item.js")(v),m=r("./src/add-async.js")(v),p=r("./src/pagination.js")(v);d={start:function(){v.listClass="list",v.searchClass="search",v.sortClass="sort",v.page=1e4,v.i=1,v.items=[],v.visibleItems=[],v.matchingItems=[],v.searched=!1,v.filtered=!1,v.searchColumns=void 0,v.searchDelay=0,v.handlers={updated:[]},v.valueNames=[],v.utils={getByClass:s,extend:i,indexOf:a,events:o,toString:l,naturalSort:n,classes:u,getAttribute:c,toArray:f},v.utils.extend(v,e),v.listContainer="string"==typeof t?document.getElementById(t):t,v.listContainer&&(v.list=s(v.listContainer,v.listClass,!0),v.parse=r("./src/parse.js")(v),v.templater=r("./src/templater.js")(v),v.search=r("./src/search.js")(v),v.filter=r("./src/filter.js")(v),v.sort=r("./src/sort.js")(v),v.fuzzySearch=r("./src/fuzzy-search.js")(v,e.fuzzySearch),this.handlers(),this.items(),this.pagination(),v.update())},handlers:function(){for(var t in v.handlers)v[t]&&v.handlers.hasOwnProperty(t)&&v.on(t,v[t])},items:function(){v.parse(v.list),void 0!==h&&v.add(h)},pagination:function(){if(void 0!==e.pagination){!0===e.pagination&&(e.pagination=[{}]),void 0===e.pagination[0]&&(e.pagination=[e.pagination]);for(var t=0,r=e.pagination.length;t<r;t++)p(e.pagination[t])}}},this.reIndex=function(){v.items=[],v.visibleItems=[],v.matchingItems=[],v.searched=!1,v.filtered=!1,v.parse(v.list)},this.toJSON=function(){for(var t=[],e=0,r=v.items.length;e<r;e++)t.push(v.items[e].values());return t},this.add=function(t,e){if(0!==t.length){if(!e){var r=[],n=!1;void 0===t[0]&&(t=[t]);for(var s=0,i=t.length;s<i;s++){var a;n=v.items.length>v.page,a=new g(t[s],void 0,n),v.items.push(a),r.push(a)}return v.update(),r}m(t.slice(0),e)}},this.show=function(t,e){return this.i=t,this.page=e,v.update(),v},this.remove=function(t,e,r){for(var n=0,s=0,i=v.items.length;s<i;s++)v.items[s].values()[t]==e&&(v.templater.remove(v.items[s],r),v.items.splice(s,1),i--,s--,n++);return v.update(),n},this.get=function(t,e){for(var r=[],n=0,s=v.items.length;n<s;n++){var i=v.items[n];i.values()[t]==e&&r.push(i)}return r},this.size=function(){return v.items.length},this.clear=function(){return v.templater.clear(),v.items=[],v},this.on=function(t,e){return v.handlers[t].push(e),v},this.off=function(t,e){var r=v.handlers[t],n=a(r,e);return n>-1&&r.splice(n,1),v},this.trigger=function(t){for(var e=v.handlers[t].length;e--;)v.handlers[t][e](v);return v},this.reset={filter:function(){for(var t=v.items,e=t.length;e--;)t[e].filtered=!1;return v},search:function(){for(var t=v.items,e=t.length;e--;)t[e].found=!1;return v}},this.update=function(){var t=v.items,e=t.length;v.visibleItems=[],v.matchingItems=[],v.templater.clear();for(var r=0;r<e;r++)t[r].matching()&&v.matchingItems.length+1>=v.i&&v.visibleItems.length<v.page?(t[r].show(),v.visibleItems.push(t[r]),v.matchingItems.push(t[r])):t[r].matching()?(v.matchingItems.push(t[r]),t[r].hide()):t[r].hide();return v.trigger("updated"),v},d.start()}},"./src/item.js":function(t){t.exports=function(t){return function(e,r,n){var s=this;this._values={},this.found=!1,this.filtered=!1;this.values=function(e,r){if(void 0===e)return s._values;for(var n in e)s._values[n]=e[n];!0!==r&&t.templater.set(s,s.values())},this.show=function(){t.templater.show(s)},this.hide=function(){t.templater.hide(s)},this.matching=function(){return t.filtered&&t.searched&&s.found&&s.filtered||t.filtered&&!t.searched&&s.filtered||!t.filtered&&t.searched&&s.found||!t.filtered&&!t.searched},this.visible=function(){return!(!s.elm||s.elm.parentNode!=t.list)},function(e,r,n){if(void 0===r)n?s.values(e,n):s.values(e);else{s.elm=r;var i=t.templater.get(s,e);s.values(i)}}(e,r,n)}}},"./src/pagination.js":function(t,e,r){var n=r("./src/utils/classes.js"),s=r("./src/utils/events.js"),i=r("./src/index.js");t.exports=function(t){var e=!1,r=function(r,s){if(t.page<1)return t.listContainer.style.display="none",void(e=!0);e&&(t.listContainer.style.display="block");var i,o=t.matchingItems.length,l=t.i,u=t.page,c=Math.ceil(o/u),f=Math.ceil(l/u),h=s.innerWindow||2,d=s.left||s.outerWindow||0,v=s.right||s.outerWindow||0;v=c-v,r.clear();for(var g=1;g<=c;g++){var m=f===g?"active":"";a.number(g,d,v,f,h)?(i=r.add({page:g,dotted:!1})[0],m&&n(i.elm).add(m),i.elm.firstChild.setAttribute("data-i",g),i.elm.firstChild.setAttribute("data-page",u)):a.dotted(r,g,d,v,f,h,r.size())&&(i=r.add({page:"...",dotted:!0})[0],n(i.elm).add("disabled"))}},a={number:function(t,e,r,n,s){return this.left(t,e)||this.right(t,r)||this.innerWindow(t,n,s)},left:function(t,e){return t<=e},right:function(t,e){return t>e},innerWindow:function(t,e,r){return t>=e-r&&t<=e+r},dotted:function(t,e,r,n,s,i,a){return this.dottedLeft(t,e,r,n,s,i)||this.dottedRight(t,e,r,n,s,i,a)},dottedLeft:function(t,e,r,n,s,i){return e==r+1&&!this.innerWindow(e,s,i)&&!this.right(e,n)},dottedRight:function(t,e,r,n,s,i,a){return!t.items[a-1].values().dotted&&(e==n&&!this.innerWindow(e,s,i)&&!this.right(e,n))}};return function(e){var n=new i(t.listContainer.id,{listClass:e.paginationClass||"pagination",item:e.item||"<li><a class='page' href='#'></a></li>",valueNames:["page","dotted"],searchClass:"pagination-search-that-is-not-supposed-to-exist",sortClass:"pagination-sort-that-is-not-supposed-to-exist"});s.bind(n.listContainer,"click",(function(e){var r=e.target||e.srcElement,n=t.utils.getAttribute(r,"data-page"),s=t.utils.getAttribute(r,"data-i");s&&t.show((s-1)*n+1,n)})),t.on("updated",(function(){r(n,e)})),r(n,e)}}},"./src/parse.js":function(t,e,r){t.exports=function(t){var e=r("./src/item.js")(t),n=function(r,n){for(var s=0,i=r.length;s<i;s++)t.items.push(new e(n,r[s]))},s=function e(r,s){var i=r.splice(0,50);n(i,s),r.length>0?setTimeout((function(){e(r,s)}),1):(t.update(),t.trigger("parseComplete"))};return t.handlers.parseComplete=t.handlers.parseComplete||[],function(){var e=function(t){for(var e=t.childNodes,r=[],n=0,s=e.length;n<s;n++)void 0===e[n].data&&r.push(e[n]);return r}(t.list),r=t.valueNames;t.indexAsync?s(e,r):n(e,r)}}},"./src/search.js":function(t){t.exports=function(t){var e,r,n,s={resetList:function(){t.i=1,t.templater.clear(),n=void 0},setOptions:function(t){2==t.length&&t[1]instanceof Array?e=t[1]:2==t.length&&"function"==typeof t[1]?(e=void 0,n=t[1]):3==t.length?(e=t[1],n=t[2]):e=void 0},setColumns:function(){0!==t.items.length&&void 0===e&&(e=void 0===t.searchColumns?s.toArray(t.items[0].values()):t.searchColumns)},setSearchString:function(e){e=(e=t.utils.toString(e).toLowerCase()).replace(/[-[\]{}()*+?.,\\^$|#]/g,"\\$&"),r=e},toArray:function(t){var e=[];for(var r in t)e.push(r);return e}},i=function(){for(var n,s=[],i=r;null!==(n=i.match(/"([^"]+)"/));)s.push(n[1]),i=i.substring(0,n.index)+i.substring(n.index+n[0].length);(i=i.trim()).length&&(s=s.concat(i.split(/\s+/)));for(var a=0,o=t.items.length;a<o;a++){var l=t.items[a];if(l.found=!1,s.length){for(var u=0,c=s.length;u<c;u++){for(var f=!1,h=0,d=e.length;h<d;h++){var v=l.values(),g=e[h];if(v.hasOwnProperty(g)&&void 0!==v[g]&&null!==v[g])if(-1!==("string"!=typeof v[g]?v[g].toString():v[g]).toLowerCase().indexOf(s[u])){f=!0;break}}if(!f)break}l.found=f}}},a=function(){t.reset.search(),t.searched=!1},o=function(o){return t.trigger("searchStart"),s.resetList(),s.setSearchString(o),s.setOptions(arguments),s.setColumns(),""===r?a():(t.searched=!0,n?n(r,e):i()),t.update(),t.trigger("searchComplete"),t.visibleItems};return t.handlers.searchStart=t.handlers.searchStart||[],t.handlers.searchComplete=t.handlers.searchComplete||[],t.utils.events.bind(t.utils.getByClass(t.listContainer,t.searchClass),"keyup",t.utils.events.debounce((function(e){var r=e.target||e.srcElement;""===r.value&&!t.searched||o(r.value)}),t.searchDelay)),t.utils.events.bind(t.utils.getByClass(t.listContainer,t.searchClass),"input",(function(t){""===(t.target||t.srcElement).value&&o("")})),o}},"./src/sort.js":function(t){t.exports=function(t){var e={els:void 0,clear:function(){for(var r=0,n=e.els.length;r<n;r++)t.utils.classes(e.els[r]).remove("asc"),t.utils.classes(e.els[r]).remove("desc")},getOrder:function(e){var r=t.utils.getAttribute(e,"data-order");return"asc"==r||"desc"==r?r:t.utils.classes(e).has("desc")?"asc":t.utils.classes(e).has("asc")?"desc":"asc"},getInSensitive:function(e,r){var n=t.utils.getAttribute(e,"data-insensitive");r.insensitive="false"!==n},setOrder:function(r){for(var n=0,s=e.els.length;n<s;n++){var i=e.els[n];if(t.utils.getAttribute(i,"data-sort")===r.valueName){var a=t.utils.getAttribute(i,"data-order");"asc"==a||"desc"==a?a==r.order&&t.utils.classes(i).add(r.order):t.utils.classes(i).add(r.order)}}}},r=function(){t.trigger("sortStart");var r={},n=arguments[0].currentTarget||arguments[0].srcElement||void 0;n?(r.valueName=t.utils.getAttribute(n,"data-sort"),e.getInSensitive(n,r),r.order=e.getOrder(n)):((r=arguments[1]||r).valueName=arguments[0],r.order=r.order||"asc",r.insensitive=void 0===r.insensitive||r.insensitive),e.clear(),e.setOrder(r);var s,i=r.sortFunction||t.sortFunction||null,a="desc"===r.order?-1:1;s=i?function(t,e){return i(t,e,r)*a}:function(e,n){var s=t.utils.naturalSort;return s.alphabet=t.alphabet||r.alphabet||void 0,!s.alphabet&&r.insensitive&&(s=t.utils.naturalSort.caseInsensitive),s(e.values()[r.valueName],n.values()[r.valueName])*a},t.items.sort(s),t.update(),t.trigger("sortComplete")};return t.handlers.sortStart=t.handlers.sortStart||[],t.handlers.sortComplete=t.handlers.sortComplete||[],e.els=t.utils.getByClass(t.listContainer,t.sortClass),t.utils.events.bind(e.els,"click",r),t.on("searchStart",e.clear),t.on("filterStart",e.clear),r}},"./src/templater.js":function(t){var e=function(t){var e,r=this,n=function(e,r){var n=e.cloneNode(!0);n.removeAttribute("id");for(var s=0,i=r.length;s<i;s++){var a=void 0,o=r[s];if(o.data)for(var l=0,u=o.data.length;l<u;l++)n.setAttribute("data-"+o.data[l],"");else o.attr&&o.name?(a=t.utils.getByClass(n,o.name,!0))&&a.setAttribute(o.attr,""):(a=t.utils.getByClass(n,o,!0))&&(a.innerHTML="")}return n},s=function(){for(var e=t.list.childNodes,r=0,n=e.length;r<n;r++)if(void 0===e[r].data)return e[r].cloneNode(!0)},i=function(t){if("string"==typeof t){if(/<tr[\s>]/g.exec(t)){var e=document.createElement("tbody");return e.innerHTML=t,e.firstElementChild}if(-1!==t.indexOf("<")){var r=document.createElement("div");return r.innerHTML=t,r.firstElementChild}}},a=function(e,r,n){var s=void 0,i=function(e){for(var r=0,n=t.valueNames.length;r<n;r++){var s=t.valueNames[r];if(s.data){for(var i=s.data,a=0,o=i.length;a<o;a++)if(i[a]===e)return{data:e}}else{if(s.attr&&s.name&&s.name==e)return s;if(s===e)return e}}}(r);i&&(i.data?e.elm.setAttribute("data-"+i.data,n):i.attr&&i.name?(s=t.utils.getByClass(e.elm,i.name,!0))&&s.setAttribute(i.attr,n):(s=t.utils.getByClass(e.elm,i,!0))&&(s.innerHTML=n))};this.get=function(e,n){r.create(e);for(var s={},i=0,a=n.length;i<a;i++){var o=void 0,l=n[i];if(l.data)for(var u=0,c=l.data.length;u<c;u++)s[l.data[u]]=t.utils.getAttribute(e.elm,"data-"+l.data[u]);else l.attr&&l.name?(o=t.utils.getByClass(e.elm,l.name,!0),s[l.name]=o?t.utils.getAttribute(o,l.attr):""):(o=t.utils.getByClass(e.elm,l,!0),s[l]=o?o.innerHTML:"")}return s},this.set=function(t,e){if(!r.create(t))for(var n in e)e.hasOwnProperty(n)&&a(t,n,e[n])},this.create=function(t){return void 0===t.elm&&(t.elm=e(t.values()),r.set(t,t.values()),!0)},this.remove=function(e){e.elm.parentNode===t.list&&t.list.removeChild(e.elm)},this.show=function(e){r.create(e),t.list.appendChild(e.elm)},this.hide=function(e){void 0!==e.elm&&e.elm.parentNode===t.list&&t.list.removeChild(e.elm)},this.clear=function(){if(t.list.hasChildNodes())for(;t.list.childNodes.length>=1;)t.list.removeChild(t.list.firstChild)},function(){var r;if("function"!=typeof t.item){if(!(r="string"==typeof t.item?-1===t.item.indexOf("<")?document.getElementById(t.item):i(t.item):s()))throw new Error("The list needs to have at least one item on init otherwise you'll have to add a template.");r=n(r,t.valueNames),e=function(){return r.cloneNode(!0)}}else e=function(e){var r=t.item(e);return i(r)}}()};t.exports=function(t){return new e(t)}},"./src/utils/classes.js":function(t,e,r){var n=r("./src/utils/index-of.js"),s=/\s+/;Object.prototype.toString;function i(t){if(!t||!t.nodeType)throw new Error("A DOM element reference is required");this.el=t,this.list=t.classList}t.exports=function(t){return new i(t)},i.prototype.add=function(t){if(this.list)return this.list.add(t),this;var e=this.array();return~n(e,t)||e.push(t),this.el.className=e.join(" "),this},i.prototype.remove=function(t){if(this.list)return this.list.remove(t),this;var e=this.array(),r=n(e,t);return~r&&e.splice(r,1),this.el.className=e.join(" "),this},i.prototype.toggle=function(t,e){return this.list?(void 0!==e?e!==this.list.toggle(t,e)&&this.list.toggle(t):this.list.toggle(t),this):(void 0!==e?e?this.add(t):this.remove(t):this.has(t)?this.remove(t):this.add(t),this)},i.prototype.array=function(){var t=(this.el.getAttribute("class")||"").replace(/^\s+|\s+$/g,"").split(s);return""===t[0]&&t.shift(),t},i.prototype.has=i.prototype.contains=function(t){return this.list?this.list.contains(t):!!~n(this.array(),t)}},"./src/utils/events.js":function(t,e,r){var n=window.addEventListener?"addEventListener":"attachEvent",s=window.removeEventListener?"removeEventListener":"detachEvent",i="addEventListener"!==n?"on":"",a=r("./src/utils/to-array.js");e.bind=function(t,e,r,s){for(var o=0,l=(t=a(t)).length;o<l;o++)t[o][n](i+e,r,s||!1)},e.unbind=function(t,e,r,n){for(var o=0,l=(t=a(t)).length;o<l;o++)t[o][s](i+e,r,n||!1)},e.debounce=function(t,e,r){var n;return e?function(){var s=this,i=arguments,a=function(){n=null,r||t.apply(s,i)},o=r&&!n;clearTimeout(n),n=setTimeout(a,e),o&&t.apply(s,i)}:t}},"./src/utils/extend.js":function(t){t.exports=function(t){for(var e,r=Array.prototype.slice.call(arguments,1),n=0;e=r[n];n++)if(e)for(var s in e)t[s]=e[s];return t}},"./src/utils/fuzzy.js":function(t){t.exports=function(t,e,r){var n=r.location||0,s=r.distance||100,i=r.threshold||.4;if(e===t)return!0;if(e.length>32)return!1;var a=n,o=function(){var t,r={};for(t=0;t<e.length;t++)r[e.charAt(t)]=0;for(t=0;t<e.length;t++)r[e.charAt(t)]|=1<<e.length-t-1;return r}();function l(t,r){var n=t/e.length,i=Math.abs(a-r);return s?n+i/s:i?1:n}var u=i,c=t.indexOf(e,a);-1!=c&&(u=Math.min(l(0,c),u),-1!=(c=t.lastIndexOf(e,a+e.length))&&(u=Math.min(l(0,c),u)));var f,h,d=1<<e.length-1;c=-1;for(var v,g=e.length+t.length,m=0;m<e.length;m++){for(f=0,h=g;f<h;)l(m,a+h)<=u?f=h:g=h,h=Math.floor((g-f)/2+f);g=h;var p=Math.max(1,a-h+1),y=Math.min(a+h,t.length)+e.length,C=Array(y+2);C[y+1]=(1<<m)-1;for(var b=y;b>=p;b--){var j=o[t.charAt(b-1)];if(C[b]=0===m?(C[b+1]<<1|1)&j:(C[b+1]<<1|1)&j|(v[b+1]|v[b])<<1|1|v[b+1],C[b]&d){var x=l(m,b-1);if(x<=u){if(u=x,!((c=b-1)>a))break;p=Math.max(1,2*a-c)}}}if(l(m+1,a)>u)break;v=C}return!(c<0)}},"./src/utils/get-attribute.js":function(t){t.exports=function(t,e){var r=t.getAttribute&&t.getAttribute(e)||null;if(!r)for(var n=t.attributes,s=n.length,i=0;i<s;i++)void 0!==n[i]&&n[i].nodeName===e&&(r=n[i].nodeValue);return r}},"./src/utils/get-by-class.js":function(t){t.exports=function(t,e,r,n){return(n=n||{}).test&&n.getElementsByClassName||!n.test&&document.getElementsByClassName?function(t,e,r){return r?t.getElementsByClassName(e)[0]:t.getElementsByClassName(e)}(t,e,r):n.test&&n.querySelector||!n.test&&document.querySelector?function(t,e,r){return e="."+e,r?t.querySelector(e):t.querySelectorAll(e)}(t,e,r):function(t,e,r){for(var n=[],s=t.getElementsByTagName("*"),i=s.length,a=new RegExp("(^|\\s)"+e+"(\\s|$)"),o=0,l=0;o<i;o++)if(a.test(s[o].className)){if(r)return s[o];n[l]=s[o],l++}return n}(t,e,r)}},"./src/utils/index-of.js":function(t){var e=[].indexOf;t.exports=function(t,r){if(e)return t.indexOf(r);for(var n=0,s=t.length;n<s;++n)if(t[n]===r)return n;return-1}},"./src/utils/to-array.js":function(t){t.exports=function(t){if(void 0===t)return[];if(null===t)return[null];if(t===window)return[window];if("string"==typeof t)return[t];if(function(t){return"[object Array]"===Object.prototype.toString.call(t)}(t))return t;if("number"!=typeof t.length)return[t];if("function"==typeof t&&t instanceof Function)return[t];for(var e=[],r=0,n=t.length;r<n;r++)(Object.prototype.hasOwnProperty.call(t,r)||r in t)&&e.push(t[r]);return e.length?e:[]}},"./src/utils/to-string.js":function(t){t.exports=function(t){return t=(t=null===(t=void 0===t?"":t)?"":t).toString()}},"./node_modules/string-natural-compare/natural-compare.js":function(t){"use strict";var e,r,n=0;function s(t){return t>=48&&t<=57}function i(t,e){for(var i=(t+="").length,a=(e+="").length,o=0,l=0;o<i&&l<a;){var u=t.charCodeAt(o),c=e.charCodeAt(l);if(s(u)){if(!s(c))return u-c;for(var f=o,h=l;48===u&&++f<i;)u=t.charCodeAt(f);for(;48===c&&++h<a;)c=e.charCodeAt(h);for(var d=f,v=h;d<i&&s(t.charCodeAt(d));)++d;for(;v<a&&s(e.charCodeAt(v));)++v;var g=d-f-v+h;if(g)return g;for(;f<d;)if(g=t.charCodeAt(f++)-e.charCodeAt(h++))return g;o=d,l=v}else{if(u!==c)return u<n&&c<n&&-1!==r[u]&&-1!==r[c]?r[u]-r[c]:u-c;++o,++l}}return o>=i&&l<a&&i>=a?-1:l>=a&&o<i&&a>=i?1:i-a}i.caseInsensitive=i.i=function(t,e){return i((""+t).toLowerCase(),(""+e).toLowerCase())},Object.defineProperties(i,{alphabet:{get:function(){return e},set:function(t){r=[];var s=0;if(e=t)for(;s<e.length;s++)r[e.charCodeAt(s)]=s;for(n=r.length,s=0;s<n;s++)void 0===r[s]&&(r[s]=-1)}}}),t.exports=i}},e={};return function r(n){if(e[n])return e[n].exports;var s=e[n]={exports:{}};return t[n](s,s.exports,r),s.exports}("./src/index.js")}();
2
+ //# sourceMappingURL=list.min.js.map
@@ -0,0 +1 @@
1
+ .molgrid-anywidget{padding:0;margin:0;width:0;height:0;max-width:0;max-height:0}
@@ -0,0 +1,21 @@
1
+ function render({ model, el }) {
2
+ const gridId = model.get("grid_id");
3
+ const globalName = "_MOLGRID_" + gridId;
4
+
5
+ // Store model reference globally so iframe can access it
6
+ window[globalName] = model;
7
+
8
+ // Add a class to the element
9
+ el.classList.add("molgrid-anywidget");
10
+
11
+ // Listen for postMessage from iframe
12
+ window.addEventListener("message", (event) => {
13
+ if (event.data && event.data.gridId === gridId && event.data.type === "MOLGRID_SELECTION") {
14
+ const selectionJson = JSON.stringify(event.data.selection);
15
+ model.set("selection", selectionJson);
16
+ model.save_changes();
17
+ }
18
+ });
19
+ }
20
+
21
+ export default { render };
cnotebook/pandas_ext.py CHANGED
@@ -1085,13 +1085,14 @@ OEDataFrameAccessor.fingerprint_similarity = _dataframe_fingerprint_similarity
1085
1085
 
1086
1086
  def _series_molgrid(
1087
1087
  self,
1088
- title_field: str = "Title",
1088
+ title: bool | str | None = True,
1089
1089
  tooltip_fields: list = None,
1090
1090
  **kwargs
1091
1091
  ):
1092
1092
  """Display molecules in an interactive grid.
1093
1093
 
1094
- :param title_field: Field for title (molecule property or DataFrame column).
1094
+ :param title: Title display mode. True uses molecule's title, a string
1095
+ specifies a field name, None/False hides titles.
1095
1096
  :param tooltip_fields: Fields for tooltip.
1096
1097
  :param kwargs: Additional arguments passed to MolGrid.
1097
1098
  :returns: MolGrid instance.
@@ -1115,7 +1116,7 @@ def _series_molgrid(
1115
1116
  mols,
1116
1117
  dataframe=df,
1117
1118
  mol_col=series.name,
1118
- title_field=title_field,
1119
+ title=title,
1119
1120
  tooltip_fields=tooltip_fields,
1120
1121
  **kwargs
1121
1122
  )
@@ -1124,14 +1125,15 @@ def _series_molgrid(
1124
1125
  def _dataframe_molgrid(
1125
1126
  self,
1126
1127
  mol_col: str,
1127
- title_field: str = "Title",
1128
+ title: bool | str | None = True,
1128
1129
  tooltip_fields: list = None,
1129
1130
  **kwargs
1130
1131
  ):
1131
1132
  """Display molecules from a column in an interactive grid.
1132
1133
 
1133
1134
  :param mol_col: Column containing molecules.
1134
- :param title_field: Column for title display.
1135
+ :param title: Title display mode. True uses molecule's title, a string
1136
+ specifies a field name, None/False hides titles.
1135
1137
  :param tooltip_fields: Columns for tooltip.
1136
1138
  :param kwargs: Additional arguments passed to MolGrid.
1137
1139
  :returns: MolGrid instance.
@@ -1145,7 +1147,7 @@ def _dataframe_molgrid(
1145
1147
  mols,
1146
1148
  dataframe=df,
1147
1149
  mol_col=mol_col,
1148
- title_field=title_field,
1150
+ title=title,
1149
1151
  tooltip_fields=tooltip_fields,
1150
1152
  **kwargs
1151
1153
  )
cnotebook/polars_ext.py CHANGED
@@ -1130,13 +1130,14 @@ DataFrameChemNamespace.copy_molecules = _dataframe_copy_molecules
1130
1130
 
1131
1131
  def _polars_series_molgrid(
1132
1132
  self,
1133
- title_field: str = "Title",
1133
+ title: bool | str | None = True,
1134
1134
  tooltip_fields: list[str] | None = None,
1135
1135
  **kwargs
1136
1136
  ) -> "MolGrid":
1137
1137
  """Display molecules in an interactive grid.
1138
1138
 
1139
- :param title_field: Field for title (molecule property).
1139
+ :param title: Title display mode. True uses molecule's title, a string
1140
+ specifies a field name, None/False hides titles.
1140
1141
  :param tooltip_fields: Fields for tooltip.
1141
1142
  :param kwargs: Additional arguments passed to MolGrid.
1142
1143
  :returns: MolGrid instance.
@@ -1148,7 +1149,7 @@ def _polars_series_molgrid(
1148
1149
 
1149
1150
  return MolGrid(
1150
1151
  mols,
1151
- title_field=title_field,
1152
+ title=title,
1152
1153
  tooltip_fields=tooltip_fields,
1153
1154
  **kwargs
1154
1155
  )
@@ -1157,14 +1158,15 @@ def _polars_series_molgrid(
1157
1158
  def _polars_dataframe_molgrid(
1158
1159
  self,
1159
1160
  mol_col: str,
1160
- title_field: str = "Title",
1161
+ title: bool | str | None = True,
1161
1162
  tooltip_fields: list[str] | None = None,
1162
1163
  **kwargs
1163
1164
  ) -> "MolGrid":
1164
1165
  """Display molecules from a column in an interactive grid.
1165
1166
 
1166
1167
  :param mol_col: Column containing molecules.
1167
- :param title_field: Column for title display.
1168
+ :param title: Title display mode. True uses molecule's title, a string
1169
+ specifies a field name, None/False hides titles.
1168
1170
  :param tooltip_fields: Columns for tooltip.
1169
1171
  :param kwargs: Additional arguments passed to MolGrid.
1170
1172
  :returns: MolGrid instance.
@@ -1189,7 +1191,7 @@ def _polars_dataframe_molgrid(
1189
1191
  mols,
1190
1192
  dataframe=pdf,
1191
1193
  mol_col=mol_col,
1192
- title_field=title_field,
1194
+ title=title,
1193
1195
  tooltip_fields=tooltip_fields,
1194
1196
  **kwargs
1195
1197
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cnotebook
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: Chemistry visualization in Jupyter Notebooks with the OpenEye Toolkits
5
5
  Author-email: Scott Arne Johnson <scott.arne.johnson@gmail.com>
6
6
  License-Expression: MIT
@@ -45,6 +45,8 @@ Dynamic: license-file
45
45
 
46
46
  **Author:** Scott Arne Johnson ([scott.arne.johnson@gmail.com](mailto:scott.arne.johnson@gmail.com))
47
47
 
48
+ **Documentation:** https://cnotebook.readthedocs.io/en/latest/
49
+
48
50
  CNotebook provides chemistry visualization for Jupyter Notebooks and Marimo using the OpenEye Toolkits.
49
51
  Import the package and your molecular data will automatically render as chemical structures without additional
50
52
  configuration.
@@ -0,0 +1,19 @@
1
+ cnotebook/__init__.py,sha256=_0b-7kP4EhCc0BkjeiQTWFRAo77AAqYeteU0v_u0ss0,13746
2
+ cnotebook/align.py,sha256=wDJy79PvRG0O_XHCAXkGv2uqp6nL65g-NO-oQSnOkpI,17926
3
+ cnotebook/context.py,sha256=HKTx0Bxz0LfleaWjBco_AoSGR2iPrVY-0OsJ_ro6O0o,19229
4
+ cnotebook/helpers.py,sha256=TCcNfykhSi77FrTQC2_2W8G9lxP0n3S7V8tEiGcE0hg,7121
5
+ cnotebook/ipython_ext.py,sha256=Z6IhHg_YP6-becgruEDiE-tVkSB0SZTUU6R2MItaVa4,1874
6
+ cnotebook/marimo_ext.py,sha256=F2WBiM0F3vLcL9vAcZesB7XgIWULd7QiWe78dQy1h3s,9790
7
+ cnotebook/pandas_ext.py,sha256=XrmL5CTQ6a_J3ruV-AK_7ZupcsUU-Y0fZ8Ml_koeOTY,43442
8
+ cnotebook/polars_ext.py,sha256=YC1Sezwk4C9Qoz4AHxsvt6D_4nwHn17wLOL5tieEGgw,47864
9
+ cnotebook/render.py,sha256=jn47U5I0t0H5R_iydhBsz_vVdtBVXyQYwrMb_XG8zy0,6143
10
+ cnotebook/grid/__init__.py,sha256=Orgb6l9C7oJD32-uBCC7gDrjUtNzJf0DLXao7FcL6GQ,1859
11
+ cnotebook/grid/grid.py,sha256=VbcoZCNT1whfcMYWjK9UQ2o9Jr5D_y2xYS54QhfwASo,51500
12
+ cnotebook/grid/static/list.min.js,sha256=NEVvGNMGqFvs6adGLZjm5sLgcuX9rGTg1wlGtA1f7M8,19487
13
+ cnotebook/grid/static/widget.css,sha256=D6uL7yh-9VoiqRfMI3rStHfbiUgBAAytQMxQzz3VVBc,81
14
+ cnotebook/grid/static/widget.js,sha256=PFq70vKj1AfOwoY3YYgaurKt6_NZrcQzrf6szMb4M6Y,693
15
+ cnotebook-2.1.2.dist-info/licenses/LICENSE,sha256=HbIgeZz-pWGC7BEnYFCQ-jfD1m_BfiosF9qjgWw64GU,1080
16
+ cnotebook-2.1.2.dist-info/METADATA,sha256=qMoZLTo7_4kjKHkNkHlZoAXhZ8Qlz6FUcAfWlAS-qtc,11924
17
+ cnotebook-2.1.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
18
+ cnotebook-2.1.2.dist-info/top_level.txt,sha256=jzkieTjQwdNKfMwnoElvDDtNPkeLMjbvWbsbkSsboo8,10
19
+ cnotebook-2.1.2.dist-info/RECORD,,
@@ -1,16 +0,0 @@
1
- cnotebook/__init__.py,sha256=C5wYJ0-6bmccYcbKCekAat08vWyk_IyqSHvob6AWfMU,13746
2
- cnotebook/align.py,sha256=wDJy79PvRG0O_XHCAXkGv2uqp6nL65g-NO-oQSnOkpI,17926
3
- cnotebook/context.py,sha256=HKTx0Bxz0LfleaWjBco_AoSGR2iPrVY-0OsJ_ro6O0o,19229
4
- cnotebook/helpers.py,sha256=TCcNfykhSi77FrTQC2_2W8G9lxP0n3S7V8tEiGcE0hg,7121
5
- cnotebook/ipython_ext.py,sha256=Z6IhHg_YP6-becgruEDiE-tVkSB0SZTUU6R2MItaVa4,1874
6
- cnotebook/marimo_ext.py,sha256=F2WBiM0F3vLcL9vAcZesB7XgIWULd7QiWe78dQy1h3s,9790
7
- cnotebook/pandas_ext.py,sha256=iOURve2nDg1z37Jq56GjP1KyvgG7BH9DYu4hlTsfIzg,43323
8
- cnotebook/polars_ext.py,sha256=AMWVGPdS8qbFH-lNcGrekPwT9vFUxZxq41Rlqx4jjB4,47725
9
- cnotebook/render.py,sha256=jn47U5I0t0H5R_iydhBsz_vVdtBVXyQYwrMb_XG8zy0,6143
10
- cnotebook/grid/__init__.py,sha256=yNcddI5PP-6BBXCNhRALvNrlgAn7UeR9ntrhmMMShu8,1804
11
- cnotebook/grid/grid.py,sha256=y-uV_cNmazI3aDWbRI2JSuOB83jhdZbiivlsPS4wBSk,51217
12
- cnotebook-2.1.0.dist-info/licenses/LICENSE,sha256=HbIgeZz-pWGC7BEnYFCQ-jfD1m_BfiosF9qjgWw64GU,1080
13
- cnotebook-2.1.0.dist-info/METADATA,sha256=adbX-E5iLz0yJwJaK_X7FUyT-FNzrYyH-e4GPIvQP5M,11860
14
- cnotebook-2.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
15
- cnotebook-2.1.0.dist-info/top_level.txt,sha256=jzkieTjQwdNKfMwnoElvDDtNPkeLMjbvWbsbkSsboo8,10
16
- cnotebook-2.1.0.dist-info/RECORD,,