/
Chemfiles.jl
145 lines (122 loc) · 4.21 KB
/
Chemfiles.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Chemfiles.jl, a modern library for chemistry file reading and writing
# Copyright (C) Guillaume Fraux and contributors -- BSD license
module Chemfiles
using DocStringExtensions
@template METHODS =
"""
$(TYPEDSIGNATURES)
$(DOCSTRING)
"""
module lib
using Chemfiles_jll
include("generated/types.jl")
include("generated/cdef.jl")
end
include("misc.jl")
include("utils.jl")
export Trajectory, Topology, Atom, UnitCell, Frame, Selection, Residue
function version()
unsafe_string(lib.chfl_version())
end
# A `Property` is a generic container for additional data stored by some
# formats
struct Property
__handle :: CxxPointer{lib.CHFL_PROPERTY}
end
"""
An `Atom` is a particle in the current [`Frame`](@ref).
An atom stores the following atomic properties:
- atom name
- atom type
- atom mass
- atom charge
The atom name is usually an unique identifier (`"H1"`, `"C_a"`) while the
atom type will be shared among all particles of the same type: `"H"`,
`"Ow"`, `"CH3"`.
"""
struct Atom
__handle :: CxxPointer{lib.CHFL_ATOM}
end
"""
A `Residue` is a group of atoms belonging to the same logical unit. They
can be small molecules, amino-acids in a protein, monomers in polymers,
*etc.*
"""
struct Residue
__handle :: CxxPointer{lib.CHFL_RESIDUE}
end
"""
A `Topology` describes the organisation of the particles in the system:
what their names are, how they are bonded together, *etc.* A `Topology`
is a list of [`Atom`](@ref)s in the system, together with the list of bonds
between the atoms.
"""
struct Topology
__handle :: CxxPointer{lib.CHFL_TOPOLOGY}
end
"""
A `UnitCell` describes the bounding box of a system. It is represented by
a 3x3 matrix containing the base vectors `a`, `b` and `c`.
"""
struct UnitCell
__handle :: CxxPointer{lib.CHFL_CELL}
end
"""
A `Frame` holds data for one step of a simulation. As not all formats
provide all the types of information, some fields may be initialized to a
default value. A `Frame` may contain the following data:
- Positions for all the atoms in the system;
- Velocities for all the atoms in the system;
- The [`Topology`](@ref) of the system;
- The [`UnitCell`](@ref) of the system.
"""
struct Frame
__handle :: CxxPointer{lib.CHFL_FRAME}
end
"""
A `Selection` is used to select a group of atoms. Examples of selections are
"name H" and "(x < 45 and name O) or name C". See the `full documentation
<http://chemfiles.org/chemfiles/latest/selections.html>`_ for more
information about the selection language.
"""
struct Selection
__handle :: CxxPointer{lib.CHFL_SELECTION}
end
"""
Data (either binary or string) used for in-memory reading of trajectory
DataBuffer = Union{AbstractString,Vector{UInt8},Nothing}
"""
DataBuffer = Union{AbstractString,Vector{UInt8},Nothing}
"""
A `Trajectory` represents a simulation file on the hard drive. It can read
or write one or many [`Frame`](@ref)s to this file. The file format can be
automatically determined from the extention, or manually specified.
Writing to a `Trajectory` is buffered, which means that one needs to
`close()` the trajectory and flush the buffer before being able to read the
file again.
"""
struct Trajectory
__handle :: CxxPointer{lib.CHFL_TRAJECTORY}
# hold a reference to the data to prevent garbage collection when using
# a in-memory reader
__data::DataBuffer
end
include("Property.jl")
include("Atom.jl")
include("Residue.jl")
include("Topology.jl")
include("UnitCell.jl")
include("Frame.jl")
include("Selection.jl")
include("Trajectory.jl")
include("atomsbase.jl")
function __init__()
if !startswith(version(), "0.10")
error(
"""Chemfiles.jl requires the 0.10 version of libchemfiles,
but $(version()) is installed."""
)
end
set_warning_callback(__default_warning_callback)
end
end