Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapts partially to Py3. Adds a known good npm/nodejs download channel. #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ nbmolviz.visualize(benzene)


## Dev install
Requires npm.
Requires npm. (Can get through `conda install -c conda-forge nodejs`)

$ git clone https://github.com/autodesk/notebook-molecular-visualization.git
$ cd notebook-molecular-visualization
Expand Down
5 changes: 3 additions & 2 deletions nbmolviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import os as _os

MDTVERSION = '0.8.0'
Expand Down Expand Up @@ -49,9 +50,9 @@ def _enable_nbextension():
try:
import notebook
if not notebook.nbextensions.check_nbextension('nbmolviz-js'):
print 'Installing Jupyter nbmolviz-js extension...',
print('Installing Jupyter nbmolviz-js extension...', end='')
notebook.nbextensions.install_nbextension_python('nbmolviz')
print 'done'
print('done')
notebook.nbextensions.enable_nbextension_python('widgetsnbextension')
notebook.nbextensions.enable_nbextension_python('nbmolviz')
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion nbmolviz/base/molviz2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,5 @@ def set_colors(self, colormap, render=True):
Args:
colormap(Mapping[str,List[Atoms]]): mapping of colors to atoms
"""
for color, atoms in colormap.iteritems():
for color, atoms in colormap.items():
self.set_color(atoms=atoms, color=color)
13 changes: 8 additions & 5 deletions nbmolviz/base/molviz3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
from StringIO import StringIO
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
from traitlets import Bool, Dict, Float, List, Set, Unicode

from ..utils import JSObject, translate_color, in_pixels
Expand Down Expand Up @@ -150,7 +153,7 @@ def set_colors(self, colormap):
colormap(Mapping[str,List[Atoms]]): mapping of colors to atoms
"""
styles = dict(self.styles)
for color, atoms in colormap.iteritems():
for color, atoms in colormap.items():
styles = MolViz3D.get_styles_for_color(color, atoms, styles)

self.styles = styles
Expand Down Expand Up @@ -490,9 +493,9 @@ def _grid_to_cube(grid,f=None):
print >> fobj, 1, 1
# finally, write out all the grid values
# ival = 0
for ix in xrange(grid.npoints):
for iy in xrange(grid.npoints):
for iz in xrange(grid.npoints):
for ix in range(grid.npoints):
for iy in range(grid.npoints):
for iz in range(grid.npoints):
print >> fobj, grid.fxyz[ix, iy, iz],
# ival += 1
# if ival%6 == 0: print >> fobj #newline
Expand Down
6 changes: 3 additions & 3 deletions nbmolviz/uielements/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, paramlist, paramdefs, title=None):

def reset_values(self, *args):
reset_params = set()
for name, value in self.paramlist.iteritems():
for name, value in self.paramlist.items():
if value is not None:
self.selectors[name].selector.value = value
reset_params.add(name)
Expand All @@ -82,7 +82,7 @@ def reset_values(self, *args):
self.show_relevant_fields()

def apply_values(self, *args):
for paramname, selector in self.selectors.iteritems():
for paramname, selector in self.selectors.items():
self.paramlist[paramname] = selector.selector.value
self.currentconfig.value = self._pretty_print_config()
self.show_relevant_fields()
Expand All @@ -91,7 +91,7 @@ def _pretty_print_config(self):
def cleanse(v):
if isinstance(v, (float,int)): return v
else: return str(v)
return yaml.dump({k: cleanse(v) for k, v in self.paramlist.iteritems()},
return yaml.dump({k: cleanse(v) for k, v in self.paramlist.items()},
default_flow_style=False)

def show_relevant_fields(self):
Expand Down
7 changes: 4 additions & 3 deletions nbmolviz/uielements/logwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import logging
from collections import OrderedDict

Expand Down Expand Up @@ -47,7 +48,7 @@ def display_log(obj, title=None, show=False):
"""

if not widgets_enabled:
print obj
print(obj)
return

if _current_tabs is None: # just display the damn thing
Expand Down Expand Up @@ -178,7 +179,7 @@ def _write(self, string):
self.active = True
self.value += string.strip() + '\n'
else:
print string.strip()
print(string.strip())

# temporary so that we can use this like a logging module later
error = warning = info = handled = debug = status = _write
Expand All @@ -193,7 +194,7 @@ def _capture_logging_displays(display=False, **kwargs):
else:
_current_tabs = None
enable_logging_widgets(False)
print 'Failed to create UI logging system. Logging widgets disabled'
print('Failed to create UI logging system. Logging widgets disabled')


def _finalize_logging_displays(display=True, **kwargs):
Expand Down
8 changes: 6 additions & 2 deletions nbmolviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@
'Uuh': 116, 'Uuo': 118, 'Uup': 115, 'Uuq': 114, 'Uus': 117, 'Uut': 113, 'V': 23,
'W': 74, 'Xe': 54, 'Y': 39, 'Yb': 70, 'Zn': 30, 'Zr': 40}

elements = {atnum:el for el,atnum in atomic_numbers.iteritems()}
elements = {atnum:el for el,atnum in atomic_numbers.items()}

try:
basestring
except NameError:
basestring = str

def make_layout(layout=None, **kwargs):
from ipywidgets import Layout
import traitlets

if layout is None:
layout = Layout()
for key, val in kwargs.iteritems():
for key, val in kwargs.items():
# note that this is the type of the class descriptor, not the instance attribute
if isinstance(getattr(Layout, key), traitlets.Unicode):
val = in_pixels(val)
Expand Down
4 changes: 2 additions & 2 deletions nbmolviz/viewers/viewer2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def to_graph(self, atoms):
nodes[-1].update({'atom': '',
'size': 0.5,
'color': 'darkgray'})
for neighbor, order in atom1.bond_graph.iteritems():
for neighbor, order in atom1.bond_graph.items():
if neighbor not in self.atom_indices: continue
nbr_idx = self.atom_indices[neighbor]
if nbr_idx < i1:
Expand Down Expand Up @@ -178,7 +178,7 @@ def to_graph(self, atoms):

# Add distance restraints for non-bonded atoms
for i1, atom1 in enumerate(atoms):
for i2 in xrange(i1 + 1, len(atoms)):
for i2 in range(i1 + 1, len(atoms)):
atom2 = atoms[i2]
if atom1 in atom2.bond_graph: continue

Expand Down
7 changes: 4 additions & 3 deletions nbmolviz/viewers/viewer3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import sys

import IPython.display as dsp
Expand Down Expand Up @@ -142,7 +143,7 @@ def set_color(self, color, atoms=None, _store=True):
@utils.doc_inherit
def set_colors(self, colormap, _store=True):
if _store:
for color, atoms in colormap.iteritems():
for color, atoms in colormap.items():
for atom in atoms:
self._colored_as[atom] = color
return super(GeometryViewer, self).set_colors(colormap)
Expand Down Expand Up @@ -247,8 +248,8 @@ def draw_atom_vectors(self, vecs, rescale_to=1.75,
scale = (lengths.max() / rescale_to) # units of [vec units] / angstrom
if hasattr(scale,'defunits'): scale = scale.defunits()
arrowvecs = vecarray / scale
print 'Arrow scale: {q:.3f} {unit} per {native}'.format(q=scale, unit=unit,
native=self.DISTANCE_UNITS)
print('Arrow scale: {q:.3f} {unit} per {native}'.format(q=scale, unit=unit,
native=self.DISTANCE_UNITS))
shapes = []
for atom, vecarray in zip(self.mol.atoms, arrowvecs):
if vecarray.norm() < 0.2: continue
Expand Down
3 changes: 2 additions & 1 deletion nbmolviz/widget_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import sys

def can_use_widgets():
Expand All @@ -19,7 +20,7 @@ def can_use_widgets():
return False

if int(ipy.__version__.split('.')[0]) < 6:
print 'WARNING: widgets require ipywidgets 6.0 or later'
print('WARNING: widgets require ipywidgets 6.0 or later')
return False

return True
Expand Down
10 changes: 6 additions & 4 deletions nbmolviz/widgets/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import collections

import ipywidgets as ipy
Expand All @@ -35,9 +36,10 @@ def indices_to_value(self, atom_indices, atoms):
Turn atom objects into a value to display
"""
def atoms_to_value(self, atoms):
if len(atoms) == 0:
natom = len(list(atoms))
if natom == 0:
return 'No selection'
elif len(atoms) == 1:
elif natom == 1:
atom = atoms[0]
res = atom.residue
chain = res.chain
Expand All @@ -49,7 +51,7 @@ def atoms_to_value(self, atoms):
lines.append("<b>Atom</b> %s (%s), index %d<br>" % (atom.name, atom.symbol, atom.index))
return '\n'.join(lines)

elif len(atoms) > 1:
elif natom > 1:
atstrings = ['<b>%s</b>, index %s / res <b>%s</b>, index %s / chain <b>%s</b>' %
(a.name, a.index, a.residue.resname, a.residue.index, a.chain.name)
for a in atoms]
Expand Down Expand Up @@ -170,7 +172,7 @@ def parse_value(self, *args):
match = utils.GETFLOAT.search(s)
if match is None:
self.readout.value = self.formatstring.format(self.slider.value)
print "Couldn't parse string %s" % s
print("Couldn't parse string %s" % s)
return
else:
f = float(s[match.start():match.end()])
Expand Down
5 changes: 3 additions & 2 deletions nbmolviz/widgets/parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
This is currently tied to ambertools and tleap! It will need to be made generic if/when
another method for assigning forcefields is added.
"""
from __future__ import print_function
import collections

import ipywidgets as ipy
Expand All @@ -35,9 +36,9 @@ def show_parameterization_results(errormessages, molin, molout=None):
uibase.display_log(report, title='ERRORS/WARNINGS', show=True)

else:
print 'Forcefield assignment: %s' % ('Success' if molout is not None else 'Failure')
print('Forcefield assignment: %s' % ('Success' if molout is not None else 'Failure'))
for err in errormessages:
print utils.html_to_text(err.desc)
print(utils.html_to_text(err.desc))



Expand Down
3 changes: 2 additions & 1 deletion nbmolviz/widgets/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO: catch and log event exceptions
from __future__ import print_function
import ipywidgets as ipy

from moldesign import utils
Expand Down Expand Up @@ -126,7 +127,7 @@ def handle_selection_event(self, selection):
if self.value_selects in selection:
self.value = selection[self.value_selects]
except Exception as exc:
print 'ERROR: (ignored) %s' % exc
print('ERROR: (ignored) %s' % exc)
self.__hold_fire = False


Expand Down
2 changes: 1 addition & 1 deletion nbmolviz/widgets/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def animate(self, fps=None):
fps = mdt.utils.if_not_none(fps, self.default_fps)
self.slider.value = 0
spf = 1.0 / fps
for i in xrange(self.viewer.num_frames):
for i in range(self.viewer.num_frames):
t0 = time.time()
self.slider.value = i
dt = time.time() - t0
Expand Down