Ticket #1470: test_pdb.py

File test_pdb.py, 740 bytes (added by Tom Goddard, 4 years ago)

Example python script using ChimeraX wheel to open a PDB and save an image.

Line 
1# Create session
2from chimerax.core.session import Session
3session = Session('cx standalone', offscreen_rendering = True)
4
5# Setup residue template path.
6from chimerax.atomic import initialize_atomic
7initialize_atomic(session)
8
9# Open PDB file
10from chimerax.pdb import open_pdb
11from os.path import expanduser
12models, msg = open_pdb(session, expanduser('~/Downloads/ChimeraX/PDB/1a0s.pdb'))
13session.models.add(models)
14
15s = models[0]
16print('%s has %d atoms, %d bonds, %d residues, centroid %s, average atom radius %.2f'
17 % (s.name, s.num_atoms, s.num_bonds, s.num_residues,
18 tuple(s.atoms.coords.mean(axis=0)), s.atoms.radii.mean()))
19
20# Save an image
21from chimerax.image_formats import save_image
22save_image(session, 'test.png')