def convert_object_to_pythreejs(object):
    """
    Cases for the conversion
    :return:
    """
    obs = []
    if object["type"] == "spheres":
        for ipos in object["positions"]:
            obj3d = Mesh(
                geometry=SphereBufferGeometry(radius=object["radius"],
                                              widthSegments=32,
                                              heightSegments=16),
                material=MeshLambertMaterial(color=object["color"]),
                position=ipos,
            )
            obs.append(obj3d)
    elif object["type"] == "cylinders":
        for ipos in object["positionPairs"]:
            obj3d = _get_cylinder_from_vec(ipos[0],
                                           ipos[1],
                                           color=object["color"])
            obs.append(obj3d)
    elif object["type"] == "lines":
        for ipos, jpos in zip(object["positions"][::2],
                              object["positions"][1::2]):
            obj3d = _get_line_from_vec(ipos, jpos)
            obs.append(obj3d)
    else:
        warnings.warn(
            f"Primitive type {object['type']} has not been implemented for this renderer."
        )
    return obs
Ejemplo n.º 2
0
def convert_object_to_pythreejs(object):
    """
    Cases for the conversion
    :return:
    """
    obs = []
    if object['type'] == 'spheres':
        for ipos in object['positions']:
            obj3d = Mesh(geometry=SphereBufferGeometry(radius=object['radius'],
                                                       widthSegments=32,
                                                       heightSegments=16),
                         material=MeshLambertMaterial(color=object["color"]),
                         position=ipos)
            obs.append(obj3d)
    elif object['type'] == 'cylinders':
        for ipos in object['positionPairs']:
            obj3d = _get_cylinder_from_vec(ipos[0],
                                           ipos[1],
                                           color=object['color'])
            obs.append(obj3d)
    elif object['type'] == 'lines':
        for ipos, jpos in zip(object['positions'][::2],
                              object['positions'][1::2]):
            obj3d = _get_line_from_vec(ipos, jpos)
            obs.append(obj3d)
    return obs
Ejemplo n.º 3
0
def _get_spheres(ctk_scene, d_args=None):

    if ctk_scene.phiEnd and ctk_scene.phiStart:
        phi_length = ctk_scene.phiEnd - ctk_scene.phiStart
    else:
        phi_length = np.pi * 2

    return [
        Mesh(
            geometry=SphereBufferGeometry(
                radius=ctk_scene.radius,
                phiStart=ctk_scene.phiStart or 0,
                phiLength=phi_length,
                widthSegments=32,
                heightSegments=32,
            ),
            material=MeshLambertMaterial(color=ctk_scene.color),
            position=tuple(ipos),
        ) for ipos in ctk_scene.positions
    ]
Ejemplo n.º 4
0
"""
Link up the StructureMoleculeComponent objects to pythreejs
Also includes some helper functions for draw addition objects using pythreejs
"""

from pythreejs import MeshLambertMaterial, Mesh, SphereBufferGeometry, CylinderBufferGeometry, Object3D, LineSegments2, LineSegmentsGeometry, LineMaterial, Scene, AmbientLight, Renderer, OrbitControls, OrthographicCamera, DirectionalLight
from crystal_toolkit.components.structure import StructureMoleculeComponent
from IPython.display import display
from scipy.spatial.transform import Rotation as R
import numpy as np
ball = Mesh(geometry=SphereBufferGeometry(radius=1,
                                          widthSegments=32,
                                          heightSegments=16),
            material=MeshLambertMaterial(color='red'),
            position=[0, 1, 0])


def traverse_scene_object(scene_data, parent=None):
    """
    Recursivesly populate a scene object with tree of children
    :param scene_data:
    :param parent:
    :return:
    """
    for sub_object in scene_data["contents"]:
        if "type" in sub_object.keys():
            parent.add(convert_object_to_pythreejs(sub_object))
        else:
            new_parent = Object3D(name=sub_object["name"])
            if parent is None:
                parent = new_parent