using this .cif file:
https://files.rcsb.org/download/1MSC.cif and parsing in with https://pypi.org/project/pdbx-mmcif/
with this code (main.py) that uses Vpython 7.6.1 in python3:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 11 17:40:03 2020
@author: Pietro
"""
import sys
from pdbx.reader.PdbxReader import PdbxReader
import time
from vpython import *
scene = canvas(title='Examples of Tetrahedrons',
width=800, height=800,
center=vector(0,0,0), background=color.black)
openz = open('./1msc.cif')
pRd = PdbxReader(openz)
data = []
pRd.read(data)
block = data[0]
atomsite = block.getObj("atom_site")
i=0
while True:
atom = atomsite.getValue("group_PDB",i)
atomid = atomsite.getValue('label_atom_id',i)
if atom =='ATOM':
if atomid == 'CA':
aa = sphere(pos=vector(float(atomsite.getValue('Cartn_x',i)),float(atomsite.getValue('Cartn_y',i)),
float(atomsite.getValue('Cartn_z',i))),radius=0.5)
i +=1
else:
break
print('fine')
I can show CA atoms in space as spheres. What I am missing is how to access the singles spheres ( objects as I understood) created by vpython, to be able to apply something like
sphere-object-number-1.color = color.red
sphere-object-number-1.color = color.blue
obviusly not in the same loop I created to display all the spheres ? Please be kind I am not a Python expert.
A standard method is to make a list atoms = [] and when you create a sphere add it to the list, as atoms.append(sphere(.....)). Then you access the nth sphere with atoms[n], where n runs from 0 to atoms.length-1.