Skip to content

Commit

Permalink
Removed py3dmol as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWeaving committed Oct 8, 2024
1 parent 7fe767d commit d33d50e
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 62 deletions.
16 changes: 1 addition & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ ray = "2.10"
sphinx-design = "^0.5.0"
myst-nb = "^0.17.2"
sphinx-copybutton = "^0.5.2"
py3dmol = "^2.0.4"
scipy = "1.9.3"
urllib3 = "1.26.6"

Expand Down
34 changes: 0 additions & 34 deletions symmer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import scipy as sp
from typing import List, Tuple, Union
from functools import reduce
import py3Dmol
from scipy.sparse import csr_matrix
from scipy.sparse import kron as sparse_kron
from symmer.operators.utils import _rref_binary
Expand Down Expand Up @@ -225,39 +224,6 @@ def gram_schmidt_from_quantum_state(state:Union[np.array, list, QuantumState]) -

return M


def Draw_molecule(
xyz_string: str, width: int = 400, height: int = 400, style: str = "sphere"
) -> py3Dmol.view:
"""Draw molecule from xyz string.
Note if molecule has unrealistic bonds, then style should be sphere. Otherwise stick style can be used
which shows bonds.
TODO: more styles at http://3dmol.csb.pitt.edu/doc/$3Dmol.GLViewer.html
Args:
xyz_string (str): xyz string of molecule
width (int): width of image
height (int): Height of image
style (str): py3Dmol style ('sphere' or 'stick')
Returns:
view (py3dmol.view object). Run view.show() method to print molecule.
"""
view = py3Dmol.view(width=width, height=height)
view.addModel(xyz_string, "xyz")
if style == "sphere":
view.setStyle({'sphere': {"radius": 0.2}})
elif style == "stick":
view.setStyle({'stick': {}})
else:
raise ValueError(f"unknown py3dmol style: {style}")

view.zoomTo()
return view


def get_sparse_matrix_large_pauliwordop(P_op: PauliwordOp) -> csr_matrix:
"""
In order to build the sparse matrix (e.g. above 18 qubits), this function goes through each pauli term
Expand Down
13 changes: 1 addition & 12 deletions tests/test_symmer_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from symmer.operators import PauliwordOp, QuantumState
from symmer.utils import (exact_gs_energy, random_anitcomm_2n_1_PauliwordOp,Draw_molecule,
from symmer.utils import (exact_gs_energy, random_anitcomm_2n_1_PauliwordOp,
tensor_list, gram_schmidt_from_quantum_state, product_list,
get_sparse_matrix_large_pauliwordop, matrix_allclose)
import numpy as np
from openfermion import QubitOperator
import py3Dmol

H2_sto3g = {'qubit_encoding': 'jordan_wigner',
'unit': 'angstrom',
Expand Down Expand Up @@ -446,16 +445,6 @@ def test_gram_schmidt_from_quantum_state_numpy_array():
assert np.allclose(U_gram[:, 0], psi_norm), 'first column of U_gram not correct'
assert np.allclose(U_gram @ U_gram.conj().T, np.eye(2 ** nq)), 'U_gram not unitary'


def test_Draw_molecule():

xyz = H2_sto3g['geometry']
viewer_sphere = Draw_molecule(xyz, width=400, height=400, style='sphere')
assert isinstance(viewer_sphere, py3Dmol.view)

viewer_stick = Draw_molecule(xyz, width=400, height=400, style='stick')
assert isinstance(viewer_stick, py3Dmol.view)

def test_get_sparse_matrix_large_pauliwordop():
for nq in range(2,6):
n_terms = 10*nq
Expand Down

0 comments on commit d33d50e

Please sign in to comment.