<jupyter_start><jupyter_text><jupyter_code>!pip install x3d
pip install x3d --upgrade
from x3d import x3d
newModel=x3d.X3D(profile='Interchange',version='3.3', 
             head=x3d.head(
    children=[
    x3d.meta(content='RedSphereBlueBox.x3d',name='title'),
    x3d.meta(content='X3D encodings example: show simple Shapes, including different Materials and geometry.',name='description'),
    x3d.meta(content='<NAME> and <NAME>',name='creator'),
    x3d.meta(content='1 June 2002',name='created'),
    x3d.meta(content='28 October 2019',name='modified'),
    x3d.meta(content='X3D encodings, ISO/IEC 19776-1.3, Part 1: XML encoding, Annex C.2 Simple example',name='specificationSection'),
    x3d.meta(content='https://www.web3d.org/documents/specifications/19776-1/V3.3/Part01/examples.html#SimpleExample',name='specificationUrl'),
    x3d.meta(content='https://www.web3d.org/x3d/content/examples/Basic/X3dSpecifications/RedSphereBlueBox.x3d',name='identifier'),
    x3d.meta(content='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit',name='generator'),
    x3d.meta(content='../license.html',name='license')]),
  Scene=x3d.Scene(
    children=[
    x3d.WorldInfo(title='RedSphereBlueBox.x3d'),
    x3d.Transform(
      children=[
      x3d.NavigationInfo(headlight=False,type=["EXAMINE"]),
      x3d.DirectionalLight(),
      x3d.Transform(translation=(3.3,0.0,1.0),
        children=[
        x3d.Shape(
          geometry=x3d.Sphere(radius=2.3),
          appearance=x3d.Appearance(
            material=x3d.Material(diffuseColor=(1.0,0.0,0.0))))]),
      x3d.Transform(rotation=(0.0,0.707,0.707,0.9),translation=(-2.4,0.2,1.0),
        children=[
        x3d.Shape(
          geometry=x3d.Box(),
          appearance=x3d.Appearance(
            material=x3d.Material(diffuseColor=(0.0,0.0,1.0))))])])])
) # X3D model complete

if        x3d.metaDiagnostics(newModel): # built-in utility method in X3D class
    print(metaDiagnostics(newModel))
print('check  newModel.XML() serialization...')
newModelXML = newModel.XML() # test export method XML() for exceptions
#print(newModelXML) # debug
x3d.Arc2D
print(newModel)
newModel
print ("python x3d.py load successful for RedSphereBlueBox.py")
! pip install qiskit
from qiskit.visualization import plot_bloch_vector
%matplotlib inline

plot_bloch_vector([0,1,0], title="New Bloch Sphere")
from IPython.display import Image
from IPython.core.display import HTML 
bloch_sphere = '''
<head>
 <script type="text/javascript" src="https://www.x3dom.org/download/x3dom.js"></script>
 <link rel="stylesheet" type="text/css" href="https://www.x3dom.org/download/x3dom.css"></link>
</head>
<x3d width="500px" height="400px">
 <meta name='title' content='CoordinateAxes.x3d'/>
  <scene>
   <shape>
    <appearance>
     <material diffuseColor="1 2 3"></material>
    </appearance>
    <sphere lit='true' solid='false'></sphere>
   </shape>
	<inline url="myScene.x3d"> </inline> 
   <Background skyColor='1 1 1'/>
  </scene>
</x3d>
'''

bloch_sphere1 = '''
<head>
 <script type="text/javascript" src="https://www.x3dom.org/download/x3dom.js"></script>
 <link rel="stylesheet" type="text/css" href="https://www.x3dom.org/download/x3dom.css"></link>
</head>
<x3d width="500px" height="400px">
 <meta name='title' content='CoordinateAxes.x3d'/>
  <scene>
   <Group DEF='ArrowGreen'>
          <Shape>
            <Cylinder DEF='ArrowCylinder' radius='.025' top='false'lit='true' solid='false'/>
            <Appearance DEF='Green'>
              <Material diffuseColor='.1 .6 .1' emissiveColor='.5 .2 .05'/>
            </Appearance>
          </Shape>
          <Transform translation='0 1 0'>
            <Shape>
              <Cone DEF='ArrowCone' bottomRadius='.05' height='.1'/>
              <Appearance USE='Green'/>
            </Shape>
          </Transform>
        </Group>
  </scene>
</x3d>
  '''

scrap = '''
<coordinateAxes></coordinateAxes>
    <Coordinate point="0 0 0, 1 0 0, 1 0 -1, 0.5 1 0"/>
    <box lit='true' solid='true'/>
'''

axes3d = '''<head>
 <script type="text/javascript" src="https://www.x3dom.org/download/x3dom.js"></script>
 <link rel="stylesheet" type="text/css" href="https://www.x3dom.org/download/x3dom.css"></link>
 <link rel="stylesheet" type="text/css" href="https://create3000.github.io/code/x_ite/4.6.14/dist/x_ite.css"/>
<script type="text/javascript" src="https://create3000.github.io/code/x_ite/4.6.14/dist/x_ite.min.js"></script>
</head>
<X3D profile='Immersive' version='3.3'  xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' https://www.web3d.org/specifications/x3d-3.3.xsd '>
<head>
<meta name='title' content='CoordinateAxesNSEW.x3d'/>
<meta name='creator' content='<NAME> and <NAME>'/>
<meta name='created' content='14 July 2000'/>
<meta name='modified' content='20 October 2019'/>
<meta name='description' content='X Y Z axis arrows and labels in X3D coordinate system. See CoordinateAxesExample for use as an Inline coordinate-system reference frame.'/>
<meta name='Image' content='CoordinateAxesNSEW.png'/>
<meta name='Image' content='CoordinateAxesNSEW.WhiteBackground.png'/>
<meta name='reference' content='CoordinateAxes.x3d'/>
<meta name='reference' content='CoordinateAxesInlineExample.x3d'/>
<meta name='reference' content=' http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter03Grouping/CoordinateAxes.x3d '/>
<meta name='reference' content=' http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter03Grouping/CoordinateAxesNSEW.x3d '/>
<meta name='reference' content=' https://savage.nps.edu/Savage/Tools/Authoring/CoordinateAxes.x3d '/>
<meta name='reference' content=' https://savage.nps.edu/Savage/Tools/Authoring/CoordinateAxesNSEW.x3d '/>
<meta name='identifier' content=' http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter03Grouping/CoordinateAxesNSEW.x3d '/>
<meta name='reference' content=' https://www.web3d.org/x3d/specifications/ISO-IEC-FDIS-19775-1.2-X3D-AbstractSpecification/Part01/components/geodata.html#GeoLocation '/>
<meta name='generator' content='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='license' content=' ../license.html'/>
</head>
<!--
Index for DEF nodes : ArrowBlue, ArrowCone, ArrowCylinder, ArrowGreen, ArrowRed, Blue, DoNotCollideWithVisualizationWidget, Green, LABEL_APPEARANCE, LABEL_FONT, LABEL_FONT_TOP, Red
-->
<Scene>
<WorldInfo title='CoordinateAxesNSEW.x3d'/>
<Collision DEF='DoNotCollideWithVisualizationWidget' enabled='false'>
<!-- Invoke CoordinateAxes in other scenes as an Inline child inside a scaling Transform node, at the topmost level of the scene graph. -->
<!-- This NavigationInfo allows examine mode and will be overridden by any parent scene. -->
<!-- Each arrow goes from +1m to -1m to allow linear scaling to fit a scene -->
<!-- Note each label rotates about the scene's vertical Y axis for consistency, enabling local orientation by user -->
<!-- From X3D Abstract Specification Section 25.3.3 GeoLocation: "In addition to placing a X3D model at the correct geospatial location, the GeoLocation node will also adjust the orientation of the model appropriately. The standard X3D coordinate system specifies that the +Y axis = up, +Z = out of the screen, and +X = towards the right. The GeoLocation node will set the orientation so that the +Y axis is the up direction for that local area (the normal to the tangent plane on the ellipsoid), -Z points towards the north pole, and +X is east." -->
<Group>
<!-- Vertical Y arrow and label -->
<Group DEF='ArrowGreen'>
<Shape>
<Cylinder DEF='ArrowCylinder' bottom='false' radius='.025' top='false'/>
<Appearance DEF='Green'>
<Material diffuseColor='.1 .6 .1' emissiveColor='.05 .2 .05'/>
</Appearance>
</Shape>
<Transform translation='0 1 0'>
<Shape>
<Cone DEF='ArrowCone' bottomRadius='.05' height='.1'/>
<Appearance USE='Green'/>
</Shape>
</Transform>
</Group>
<Transform translation='0 1.08 0'>
<Billboard>
<Shape>
<Appearance DEF='LABEL_APPEARANCE'>
<Material diffuseColor='1 1 .3' emissiveColor='.33 .33 .1'/>
</Appearance>
<Text string='"+Y" "Up"'>
<FontStyle DEF='LABEL_FONT_TOP' family='"SANS"' justify='"MIDDLE" "END"' size='.2'/>
</Text>
</Shape>
</Billboard>
</Transform>
<Transform translation='0 -1.08 0'>
<Billboard>
<Shape>
<Appearance USE='LABEL_APPEARANCE'/>
<Text string='"-Y" "Down"'>
<FontStyle USE='LABEL_FONT_TOP'/>
</Text>
</Shape>
</Billboard>
</Transform>
</Group>
<Transform rotation='0 0 1 -1.57079'>
<!-- Horizontal X arrow and label -->
<Group>
<Group DEF='ArrowRed'>
<Shape>
<Cylinder USE='ArrowCylinder'/>
<Appearance DEF='Red'>
<Material diffuseColor='.7 .1 .1' emissiveColor='.33 0 0'/>
</Appearance>
</Shape>
<Transform translation='0 1 0'>
<Shape>
<Cone USE='ArrowCone'/>
<Appearance USE='Red'/>
</Shape>
</Transform>
</Group>
<Transform rotation='0 0 1 1.57079' translation='.072 1.1 0'>
<!-- note label rotated back to original coordinate frame -->
<Billboard>
<Shape>
<Appearance USE='LABEL_APPEARANCE'/>
<Text string='"+X" "East"'>
<FontStyle DEF='LABEL_FONT' family='"SANS"' justify='"MIDDLE" "MIDDLE"' size='.2'/>
</Text>
</Shape>
</Billboard>
</Transform>
<Transform rotation='0 0 1 1.57079' translation='.072 -1.1 0'>
<!-- note label rotated back to original coordinate frame -->
<Billboard>
<Shape>
<Appearance USE='LABEL_APPEARANCE'/>
<Text string='"-X" "West"'>
<FontStyle USE='LABEL_FONT'/>
</Text>
</Shape>
</Billboard>
</Transform>
</Group>
</Transform>
<Transform rotation='1 0 0 1.57079'>
<!-- Perpendicular Z arrow and label, note right-hand rule -->
<Group>
<Group DEF='ArrowBlue'>
<Shape>
<Cylinder USE='ArrowCylinder'/>
<Appearance DEF='Blue'>
<Material diffuseColor='.3 .3 1' emissiveColor='.1 .1 .33'/>
</Appearance>
</Shape>
<Transform translation='0 1 0'>
<Shape>
<Cone USE='ArrowCone'/>
<Appearance USE='Blue'/>
</Shape>
</Transform>
</Group>
<Transform rotation='1 0 0 -1.57079' translation='0 1.1 .072'>
<!-- note label rotated back to original coordinate frame -->
<Billboard>
<Shape>
<Appearance USE='LABEL_APPEARANCE'/>
<Text string='"+Z" "South"'>
<FontStyle USE='LABEL_FONT'/>
</Text>
</Shape>
</Billboard>
</Transform>
<Transform rotation='1 0 0 -1.57079' translation='0 -1.1 .072'>
<!-- note label rotated back to original coordinate frame -->
<Billboard>
<Shape>
<Appearance USE='LABEL_APPEARANCE'/>
<Text string='"-Z" "North"'>
<FontStyle USE='LABEL_FONT'/>
</Text>
</Shape>
</Billboard>
</Transform>
</Group>
</Transform>
</Collision>
</Scene>
</X3D>
'''


HTML(bloch_sphere)
from IPython.display import HTML

javascript = '''
<script type="text/javascript" src="https://www.x3dom.org/download/x3dom.js" > </script> 
<link rel="stylesheet" type="text/css" href="https://www.x3dom.org/download/x3dom.css" ></link> 
<x3d width="300px" height="200px">
       <Scene>
    <Collision DEF='DoNotCollideWithVisualizationWidget' enabled='true'>
      <!-- Invoke CoordinateAxes in other scenes as an Inline child inside a scaling Transform node, at the topmost level of the scene graph. -->
      <!-- This NavigationInfo allows examine mode and will be overridden by any parent scene. -->
      <!-- Each arrow goes from +1m to -1m to allow linear scaling to fit a scene -->
      <!-- Note each label rotates about the scene's vertical Y axis for consistency, enabling local orientation by user -->
      <Group>
        <!-- Vertical Y arrow and label -->
        <Group DEF='ArrowGreen'>
          <Shape>
            <Cylinder DEF='ArrowCylinder' radius='.025' top='false'/>
            <Appearance DEF='Green'>
              <Material diffuseColor='.1 .6 .1' emissiveColor='.05 .2 .05'/>
            </Appearance>
          </Shape>
          <Transform translation='0 1 0'>
            <Shape>
              <Cone DEF='ArrowCone' bottomRadius='.05' height='.1'/>
              <Appearance USE='Green'/>
            </Shape>
          </Transform>
        </Group>
        <Transform translation='0 1.08 0'>
          <Billboard>
            <Shape>
              <Appearance DEF='LABEL_APPEARANCE'>
                <Material diffuseColor='1 1 .3' emissiveColor='.33 .33 .1'/>
              </Appearance>
              <Text string='"Y"'>
                <FontStyle DEF='LABEL_FONT' family='"SANS"' justify='"MIDDLE" "MIDDLE"' size='.2'/>
              </Text>
            </Shape>
          </Billboard>
        </Transform>
      </Group>
      <Transform rotation='0 0 1 -1.57079'>
        <!-- Horizontal X arrow and label -->
        <Group>
          <Group DEF='ArrowRed'>
            <Shape>
              <Cylinder USE='ArrowCylinder'/>
              <Appearance DEF='Red'>
                <Material diffuseColor='.7 .1 .1' emissiveColor='.33 0 0'/>
              </Appearance>
            </Shape>
            <Transform translation='0 1 0'>
              <Shape>
                <Cone USE='ArrowCone'/>
                <Appearance USE='Red'/>
              </Shape>
            </Transform>
          </Group>
          <Transform rotation='0 0 1 1.57079' translation='.072 1.1 0'>
            <!-- note label rotated back to original coordinate frame -->
            <Billboard>
              <Shape>
                <Appearance USE='LABEL_APPEARANCE'/>
                <Text string='"X"'>
                  <FontStyle USE='LABEL_FONT'/>
                </Text>
              </Shape>
            </Billboard>
          </Transform>
        </Group>
      </Transform>
      <Transform rotation='1 0 0 1.57079'>
        <!-- Perpendicular Z arrow and label, note right-hand rule -->
        <Group>
          <Group DEF='ArrowBlue'>
            <Shape>
              <Cylinder USE='ArrowCylinder'/>
              <Appearance DEF='Blue'>
                <Material diffuseColor='.3 .3 1' emissiveColor='.1 .1 .33'/>
              </Appearance>
            </Shape>
            <Transform translation='0 1 0'>
              <Shape>
                <Cone USE='ArrowCone'/>
                <Appearance USE='Blue'/>
              </Shape>
            </Transform>
          </Group>
          <Transform rotation='1 0 0 -1.57079' translation='0 1.1 .072'>
            <!-- note label rotated back to original coordinate frame -->
            <Billboard>
              <Shape>
                <Appearance USE='LABEL_APPEARANCE'/>
                <Text string='"Z"'>
                  <FontStyle USE='LABEL_FONT'/>
                </Text>
              </Shape>
            </Billboard>
          </Transform>
        </Group>
      </Transform>
    </Collision>
    <appearance>
     <material diffuseColor="1 2 3"></material>
    </appearance>
    <sphere lit='true' solid='true'></sphere>
  </Scene>
</x3d>  
'''

HTML(javascript)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16729413375316585, 'fraction_numerical': 0.03634745704702581, 'mean_word_length': 3.2360104378080603, 'pattern_counts': {'":': 0, '<': 331, '<?xml version=': 0, '>': 331, 'https://': 18, 'lorem ipsum': 0, 'www.': 13, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '234571', 'license': 'MIT', 'n_tokens_mistral': 5074, 'n_tokens_neox': 4811, 'n_words': 1130, 'path': 'bloch_sphere3d.ipynb', 'repo_name': 'shishir332/quantum', 'size': '14635'}