Skip to content

Commit

Permalink
Merge 504f52d into 971aeda
Browse files Browse the repository at this point in the history
  • Loading branch information
dgasmith committed Nov 8, 2019
2 parents 971aeda + 504f52d commit 15cd628
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
15 changes: 5 additions & 10 deletions nglview/adaptor.py
Expand Up @@ -22,7 +22,7 @@
'BiopythonStructure',
'IOTBXStructure',
'IODataStructure',
'QCelementalStructure',
'QCElementalStructure',
'Psi4Structure',
'OpenbabelStructure',
'RosettaStructure',
Expand Down Expand Up @@ -137,22 +137,17 @@ def get_structure_string(self):
return ASEStructure(ase.io.read(fh.name)).get_structure_string()


class QCelementalStructure(Structure):
class QCElementalStructure(Structure):
def __init__(self, obj):
super().__init__()
self._obj = obj
self.ext = 'sdf'

def get_structure_string(self):
"""Require `ase` package
"""
import ase.io
with NamedTemporaryFile(suffix='.xyz') as fh:
with open(fh.name, 'w') as fh2:
fh2.write(self._obj.to_string('xyz'))
return ASEStructure(ase.io.read(fh.name)).get_structure_string()
return self._obj.orient_molecule().to_string('nglview-sdf')


class Psi4Structure(QCelementalStructure):
class Psi4Structure(QCElementalStructure):
pass


Expand Down
10 changes: 5 additions & 5 deletions nglview/show.py
Expand Up @@ -6,7 +6,7 @@
IOTBXStructure, MDAnalysisTrajectory, MDTrajTrajectory,
OpenbabelStructure, ParmEdTrajectory, PdbIdStructure,
ProdyStructure, ProdyTrajectory, PyTrajTrajectory,
QCelementalStructure, RosettaStructure,
QCElementalStructure, RosettaStructure,
SchrodingerStructure, SchrodingerTrajectory,
RdkitStructure,
TextStructure)
Expand Down Expand Up @@ -100,7 +100,7 @@ def show_iodata(obj, **kwargs):


def show_qcelemental(obj, **kwargs):
"""Show QCelemental's Molecule (require `ase` package).
"""Show QCElemental's Molecule.
Examples
--------
Expand All @@ -110,11 +110,11 @@ def show_qcelemental(obj, **kwargs):
... view = nv.show_qcelemental(mol)
... view
"""
return NGLWidget(QCelementalStructure(obj), **kwargs)
return NGLWidget(QCElementalStructure(obj), **kwargs)


def show_psi4(obj, **kwargs):
"""Show psi4's Molecule (require `ase` package)
"""Show Psi4's Molecule.
Examples
--------
Expand All @@ -124,7 +124,7 @@ def show_psi4(obj, **kwargs):
... view = nv.show_psi4(mol)
... view
"""
return NGLWidget(QCelementalStructure(obj), **kwargs)
return NGLWidget(QCElementalStructure(obj), **kwargs)


def show_openbabel(obj, **kwargs):
Expand Down
3 changes: 3 additions & 0 deletions nglview/tests/test_show.py
Expand Up @@ -87,6 +87,9 @@ class MockMol:
def to_string(self, format):
return '1\nHe\nHe 0.000000000000 0.000000000000 0.000000000000\n'

def orient_molecule(self):
return self

v = nglview.show_qcelemental(MockMol())
v
nglview.show_psi4(MockMol())
Expand Down
15 changes: 15 additions & 0 deletions nglview/tests/test_widget.py
Expand Up @@ -79,6 +79,12 @@
except ImportError:
has_bio = False

try:
import qcelemental
has_qcelemental = True
except ImportError:
has_qcelemental = False


def default_view():
traj = pt.load(nv.datafiles.TRR, nv.datafiles.PDB)
Expand Down Expand Up @@ -512,6 +518,15 @@ def test_show_pymatgen():
view


@unittest.skipUnless(has_qcelemental, 'skip if not having qcelemental')
def test_show_qcelemental():
import qcelemental as qcel

mol = qcel.models.Molecule.from_data("He 0 0 0")
view = nv.show_qcelemental(mol)
view


@unittest.skipUnless(has_bio, 'skip if not having biopython')
def test_show_biopython():
from Bio.PDB import PDBParser
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -193,6 +193,7 @@ def run(self):
"rdkit": ["rdkit"],
"ase": ["ase"],
"htmd": ["htmd"],
"qcelemental": ["qcelemental"],
},
'packages': set(find_packages() +
['nglview',
Expand Down

0 comments on commit 15cd628

Please sign in to comment.