Simple indexing¶

There are many ways to view the atoms in the molecule. One is to use the index, e.g.

>>> atom = mol[0]
>>> print(atom)
Atom( C:1     [  -0.02,    1.53,    0.01] )

or

>>> atom = mol.atom(0)
>>> print(atom)
Atom( C:1     [  -0.02,    1.53,    0.01] )

would access the first atom in the molecule. The num_atoms() function returns the total number of atoms.

>>> print(mol.num_atoms())
74

You can loop over all of the atoms via the atoms() function e.g.

>>> for atom in mol.atoms():
...     print(atom)
Atom( C:1     [  -0.02,    1.53,    0.01] )
Atom( C:2     [   0.00,   -0.00,    0.00] )
Atom( C:3     [   0.66,   -0.52,    1.29] )
Atom( C:4     [   1.42,    2.06,   -0.00] )
Atom( C:5     [   2.16,    1.44,    1.17] )
Atom( C:6     [   2.81,    2.24,    1.98] )
etc.

You can also loop over a slice of atoms, e.g.

>>> for atom in mol[0:5]:
...     print(atom)
Atom( C:1     [  -0.02,    1.53,    0.01] )
Atom( C:2     [   0.00,   -0.00,    0.00] )
Atom( C:3     [   0.66,   -0.52,    1.29] )
Atom( C:4     [   1.42,    2.06,   -0.00] )
Atom( C:5     [   2.16,    1.44,    1.17] )

or

>>> for atom in mol.atoms(range(0, 5)):
...     print(atom)
Atom( C:1     [  -0.02,    1.53,    0.01] )
Atom( C:2     [   0.00,   -0.00,    0.00] )
Atom( C:3     [   0.66,   -0.52,    1.29] )
Atom( C:4     [   1.42,    2.06,   -0.00] )
Atom( C:5     [   2.16,    1.44,    1.17] )

or

>>> for atom in mol.atoms([0, 2, 5, 8]):
...     print(atom)
Atom( C:1     [  -0.02,    1.53,    0.01] )
Atom( C:3     [   0.66,   -0.52,    1.29] )
Atom( C:6     [   2.81,    2.24,    1.98] )
Atom( C:9     [   4.65,   -0.26,    4.19] )

Molecules can be divided into residues, chains and segments. A residue is a collection of atoms, a chain is a collection of residues, and a segment is an arbitrary, but often-larger collection of atoms within a molecule.

You can access residues, chains and segments in similar ways to accessing atoms, e.g.

>>> res = mol.residue(0)
>>> print(res)
Residue( MOL:1   num_atoms=74 )
>>> for res in mol.residues():
...     print(res)
Residue( MOL:1   num_atoms=74 )

You access atoms in a residue, chain or segment in a similar way, e.g.

>>> res = mol.residue(0)
>>> atom = res.atom(0)
>>> print(atom)
Atom( C:1     [  -0.02,    1.53,    0.01] )
>>> for atom in res.atoms([0, 2, 4]):
...     print(atom)
Atom( C:1     [  -0.02,    1.53,    0.01] )
Atom( C:3     [   0.66,   -0.52,    1.29] )
Atom( C:5     [   2.16,    1.44,    1.17] )