简体   繁体   English

Vpython访问object从pdb蛋白文件加载

[英]Vpython accessing object loaded from pdb protein file

using this.cif file:使用 this.cif 文件:

https://files.rcsb.org/download/1MSC.cif and parsing in with https://pypi.org/project/pdbx-mmcif/ https://files.rcsb.org/download/1MSC.cif并解析为https://pypi.org/project/pdbx-mmcif/

with this code (main.py) that uses Vpython 7.6.1 in python3:使用在 python3 中使用 Vpython 7.6.1 的代码 (main.py):

#!/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.我可以将空间中的 CA 原子显示为球体。 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我缺少的是如何访问由 vpython 创建的单球体(我理解的对象),以便能够应用类似的东西

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.请善待我不是 Python 专家。

A standard method is to make a list atoms = [] and when you create a sphere add it to the list, as atoms.append(sphere(.....)).一个标准的方法是创建一个列表 atoms = [] 并在创建球体时将其添加到列表中,如 atoms.append(sphere(.....))。 Then you access the nth sphere with atoms[n], where n runs from 0 to atoms.length-1.然后用 atoms[n] 访问第 n 个球体,其中 n 从 0 到 atoms.length-1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM