Skip to content

Commit 6425d64

Browse files
committed
Final 0.2 changes
1 parent cfc3e6e commit 6425d64

6 files changed

Lines changed: 176 additions & 8 deletions

File tree

README.rst

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
atomium
2+
=======
3+
4+
atomium is a molecular modeller and file parser.
5+
6+
Example
7+
-------
8+
9+
>>> import atomium
10+
>>> glucose = atomium.xyz_from_file("glucose.xyz")
11+
>>> glucose.comment()
12+
'glucose from 2gbp'
13+
>>> glucose.model()
14+
<Model (12 atoms)>
15+
>>> glucose.model().mass()
16+
168.0606
17+
18+
19+
20+
21+
22+
Installing
23+
----------
24+
25+
pip
26+
~~~
27+
28+
atomium can be installed using pip:
29+
30+
``$ pip3 install atomium``
31+
32+
atomium is written for Python 3, and does not support Python 2.
33+
34+
If you get permission errors, try using ``sudo``:
35+
36+
``$ sudo pip3 install atomium``
37+
38+
39+
Development
40+
~~~~~~~~~~~
41+
42+
The repository for atomium, containing the most recent iteration, can be
43+
found `here <http://github.com/samirelanduk/atomium/>`_. To clone the
44+
atomium repository directly from there, use:
45+
46+
``$ git clone git://github.com/samirelanduk/atomium.git``
47+
48+
49+
Requirements
50+
~~~~~~~~~~~~
51+
52+
atomium requires the Python library
53+
`geometrica <https://geometrica.samireland.com/>`_ - pip will install this
54+
automatically when it installs atomium.
55+
56+
57+
Overview
58+
--------
59+
60+
atomium allows you to open .xyz files, manipulate the model within, and save
61+
them as new .xyz files.
62+
63+
From .xyz
64+
~~~~~~~~~
65+
66+
You can load a .xyz file as follows:
67+
68+
>>> import atomium
69+
>>> glucose = atomium.xyz_from_file("glucose.xyz")
70+
>>> glucose.comment()
71+
'glucose from 2gbp'
72+
>>> glucose.model()
73+
<Model (12 atoms)>
74+
75+
The ``Xyz.comment`` property,
76+
which describes the file, and a ``Xyz.model`` property, which returns
77+
the ``Model`` the file describes.
78+
79+
The Model
80+
~~~~~~~~~
81+
82+
A ``Model`` is a representation of some molecular system and every
83+
``Atom`` within it, as described by a file.
84+
85+
As an ``AtomicStructure`` you can query its atoms, transform it in
86+
space, get its mass or formula, and get its centre of mass and radius of
87+
gyration:
88+
89+
>>> model = glucose.model()
90+
>>> model.atoms()
91+
{<C Atom at (38.553, 30.4, 50.259)>, <C Atom at (35.884, 30.895, 49.12)>, <C A
92+
tom at (36.177, 29.853, 50.124)>, <C Atom at (37.296, 30.296, 51.074)>, <O Ato
93+
m at (39.261, 32.018, 46.92)>, <C Atom at (38.357, 31.29, 49.044)>, <C Atom at
94+
(39.559, 31.209, 48.082)>, <O Atom at (37.441, 29.265, 52.113)>, <O Atom at (
95+
34.923, 29.775, 50.91)>, <O Atom at (34.968, 30.34, 48.234)>, <O Atom at (37.1
96+
55, 30.858, 48.364)>, <O Atom at (39.572, 30.954, 51.086)>}
97+
>>> model.atoms(element="O")
98+
{<O Atom at (37.441, 29.265, 52.113)>, <O Atom at (39.261, 32.018, 46.92)>, <O
99+
Atom at (37.155, 30.858, 48.364)>, <O Atom at (34.968, 30.34, 48.234)>, <O At
100+
om at (34.923, 29.775, 50.91)>, <O Atom at (39.572, 30.954, 51.086)>}
101+
>>> model.atom(element="O")
102+
<O Atom at (37.441, 29.265, 52.113)>
103+
>>> model.mass()
104+
168.0606
105+
>>> model.formula()
106+
Counter({'C': 6, 'O': 6})
107+
>>> model.translate(34, -12, 3.5)
108+
>>> model.rotate("x", 45)
109+
>>> model.atom(element="O")
110+
<O Atom at (71.441, -27.11613084494172, 51.53252799931321)>
111+
>>> model.center_of_mass()
112+
(71.39909500620611, -24.411126748628675, 50.69765860848817)
113+
>>> model.radius_of_gyration()
114+
2.3076405766875925
115+
116+
``AtomicStructure.atoms` returns all matching elements as a ``set```
117+
while ``AtomicStructure.atom`` returns the first matching atom.
118+
119+
The atoms themselves have properties for their coordinates and elements, and
120+
also for finding the distance between them:
121+
122+
>>> atom = model.atom(element="C")
123+
>>> atom.x(), atom.y(), atom.z()
124+
(72.553, -25.00258867597513, 51.02411822364008)
125+
>>> atom.element()
126+
'C'
127+
>>> atom.distance_to(model.atom(element="O"))
128+
2.4417381104450953
129+
130+
Instead of an atom, you can also provide a coordinate and get the atom's
131+
distance to that:
132+
133+
>>> atom.distance_to(model.center_of_mass())
134+
1.3371237139950765
135+
136+
137+
Saving
138+
~~~~~~
139+
140+
A model can be saved to file using:
141+
142+
>>> model.save("new.xyz", description="Modifed glucose")
143+
144+
The ``Xyz`` object itself can also be saved:
145+
146+
>>> glucose.comment("Modified glucose")
147+
>>> glucose.save("new.xyz")
148+
149+
150+
Changelog
151+
---------
152+
153+
Release 0.1.0
154+
~~~~~~~~~~~~~
155+
156+
`1 June 2017`
157+
158+
* Added basic Model and Atom classes.
159+
* Added .xyz parsing.

atomium/converters/string2xyz.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def remove_atom_num(lines):
2424
line if it is an integer.
2525
2626
:param list lines: The file lines.
27-
rtype: ``list``"""
27+
:rtype: ``list``"""
2828

2929
try:
3030
int(lines[0])
@@ -33,7 +33,7 @@ def remove_atom_num(lines):
3333

3434

3535
def parse_atom(line):
36-
"""Takes a line from an .xyz file and creates an :py:class:`Atom` from it.
36+
"""Takes a line from an .xyz file and creates an :py:class:`.Atom` from it.
3737
If the line canot be parsed it returns ``None``.
3838
3939
:param str line: The line to parse.

atomium/structures/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
from .models import Model
22
from .atoms import Atom
3+
4+
__author__ = "Sam Irelabd"
5+
__version__ = "0.1.0"

atomium/structures/molecules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def center_of_mass(self):
136136

137137
def radius_of_gyration(self):
138138
"""The radius of gyration of a structure is a measure of how extended it
139-
is. It is the root mean square deviation of the atoms from the
139+
is. It is the root mean square deviation of the atoms' distance from the
140140
structure's :py:meth:`.center_of_mass`.
141141
142142
:rtype: ``float``"""

atomium/xyz/xyz.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def model(self, model=None):
5252
def to_file_string(self):
5353
"""Returns the file text that represents this Xyx.
5454
55-
:rtype ``str``"""
55+
:rtype: ``str``"""
5656

5757
from ..converters.model2xyzstring import model_to_xyz_string
5858
return model_to_xyz_string(self._model, self._comment)
@@ -62,13 +62,18 @@ def save(self, path):
6262
"""Saves the Xyz as a .xyz file.
6363
6464
:param str path: The path to save to."""
65-
65+
6666
from ..converters.strings import string_to_file
6767
string_to_file(self.to_file_string(), path)
6868

6969

7070

7171
def xyz_from_file(path):
72+
"""Opens a .xyz file at the specified path and creates a :py:class:`.Xyz`
73+
from it.
74+
75+
:param str path: The path to open."""
76+
7277
from ..converters.strings import string_from_file
7378
from ..converters.string2xyz import string_to_xyz
7479
s = string_from_file(path)

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name="atomium",
55
version="0.1.0",
6-
description="A molecular modeller with PDB parsing.",
6+
description="A molecular modeller.",
77
url="https://atomium.samireland.com",
88
author="Sam Ireland",
99
author_email="mail@samireland.com",
@@ -22,6 +22,7 @@
2222
"Programming Language :: Python :: 3.5",
2323
"Programming Language :: Python :: 3.6",
2424
],
25-
keywords="chemistry bioinformatics proteins biochemistry molecules",
26-
packages=["atomium"]
25+
keywords="chemistry bioinformatics proteins biochemistry molecules PDB XYZ",
26+
packages=["atomium"],
27+
install_requires=["geometrica"]
2728
)

0 commit comments

Comments
 (0)