|
The
atomic hierarchy can be encoded into a compact
string. This string can be assigned to a variable,
printed or saved to a file. This string can also be
decoded to reproduce the hierarchy (see the
unpack()
method). However, the string representation
preserves only the names and organization of the
nodes. In particular, atomic properties are not
saved.
The
string representation of a hierarchy is recorded in
archive and descriptor files to preserve not only
atom and residue names but also their hierarchy.
When an archive file is read in, this string is
compared to the string representation of the
hierarchy at the target. If the strings differ then
the archive file is not appropriate for the
target.
String
representations are generated by the Python
repr()
function or the backquote operators.
The
string representation of a hierarchy is derived
recursively from a recursive definition for each
component of the hierarchy. The string
representation of an AtomGroup
object starts with the forward slash
"/"
followed by the count of local
AtomGroup
objects contained in the current Group (the value
of the numlocal
attribute). If the count is not zero the string
representation then continues with the colon
":"
and for each of the AtomGroup
objects in the current Group is listed the name of
the object (the value of the
nodename
attribute) and the string representation of that
object; the string representation of an Atom object
is followed by a colon if it is not the last item
in the list. The string representation is
terminated with the backslash
"\".
By this definition, the string representation of an
Atom object is the blank string. This is best
explained with the aid of a simple
hierarchy:
The
following hierarchy has three levels. The top of
the hierarchy is an unnamed Group which is true
of all hierarchies. Each item is assigned to a
variable (italicized) to facilitate
discussion:
[Level
0] The top of the hierarchy
(Top)
is unnamed and it contains three
items:
[Level
1] The first item
(Aa1)
is an Atom named
"A1".
[Level
1] The second
(Gb1)
is a Group named
"B1",
containing two items:
[Level
2] The first item
(Ga2)
is a Group named
"A2"
and it is empty;
[Level
2] The second item
(Ab2)
is an Atom named
"B2".
[Level
1] The last item
(Gc1)
is a Group named
"C1",
containing one item:
[Level
2] The single item
(Aa2)
is an Atom named
"A2".
|
Top
= Group ""
|
|
Aa1
= Atom "A1"
|
|
Gb1
= Group
"B1"
|
|
|
Ab2
= Atom
"B2"
|
|
|
Gc1
= Group
"C1"
|
|
Aa2
= Atom
"A2"
|
|
We
can now derive the string representation of the
entire hierarchy. The top contains three
items:
`Top`
= "/"
+ `Top.numlocal`
+ ":"
+ Aa1.nodename
+ `Aa1`
+ ":"
+ Gb1.nodename
+ `Gb1`
+ Gc1.nodename
+ `Gc1`
+ "\"
The
first item is an Atom and this is followed by a
Group; thus we add a colon as a separator. The
second and third items are both Groups so no
additional separator character is
necessary.
The
string representation of an Atom node is simply
a blank string:
`Aa1`
= ""
We
can simplify but cannot complete the
representation yet:
`Top`
= "/3:A1:B1"
+ `Gb1`
+ "C1"
+ `Gc1`
+ "\"
The
string representation for a lower level object
is obtained using the same
definition:
`Gb1`
= "/"
+ `Gb1.numlocal`
+ ":"
+ Ga2.nodename
+ `Ga2`
+ Ab2.nodename
+ `Ab2`
+ "\"
`Ab2`
= ""
The
string representation for an empty object is
very simple and to the point:
`Ga2`
= "/0\"
Continuing:
`Gb1`
= "/2:A2/0\B2\"
For
the third item:
`Gc1`
= "/"
+ `Gc1.numlocal`
+ ":"
+ Aa2.nodename
+ `Aa2`
+ "\"
`Aa2`
= ""
`Gc1`
= "/1:A2\"
Finally:
`Top`
= "/3:A1:B1/2:A2/0\B2\C1/1:A2\\"
From
the concrete example, we first obtain the string
representation of Ge1
using the backquote operators and save the string
in the variable Se1.
Then we print the string:
>>> Se1 = `Ge1` >>> print Se1 /2:f2/2:e3:f3\g2/0\\
|
It
can be seen that this string is a substring of the
string representation of the entire hierarchy. This
reflects the fact that this is a sub-hierarchy of
the full hierarchy.
|