/
atom_binding.cpp
168 lines (136 loc) · 6.01 KB
/
atom_binding.cpp
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
This is the main file of steinhardt module where the bindings of the classes System and Atom are
provided. Additionally, the docstrings for the functions are also provided here. The docstrings should
be elaborate and ideally follow pep-8 conventions.
*/
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <vector>
#include <string>
#include "atom.h"
namespace py = pybind11;
using namespace std;
vector<double> vv{0,0,0};
PYBIND11_MODULE(catom, m) {
py::options options;
options.disable_function_signatures();
//bindings for Atom class
//------------------------------------------------------------------
py::class_<Atom>(m,"Atom", R"mydelimiter(
Class to store atom details.
Parameters
----------
pos : list of floats of length 3
position of the `Atom`, default [0,0,0]
id : int
id of the `Atom`, default 0
type : int
type of the `Atom`, default 1
Notes
-----
A pybind11 class for holding the properties of a single atom. Various properties of the atom
can be accessed through the attributes and member functions which are described below in detail. Atoms can
be created individually or directly by reading a file. Check the examples for more
details on how atoms are created. For creating atoms directly from an input file check
the documentation of :class:`~pyscal.core.System` class.
Although an `Atom` object can be created independently, `Atom` should be thought of
inherently as members of the :class:`~pyscal.core.System` class. All the properties that define an atom are
relative to the parent class. :class:`~pyscal.core.System` has a list of all atoms. All the properties of an
atom, hence should be calculated through :class:`~pyscal.core.System`.
Examples
--------
>>> #method 1 - individually
>>> atom = Atom()
>>> #now set positions of the atoms
>>> atom.pos = [23.0, 45.2, 34.2]
>>> #now set id
>>> atom.id = 23
>>> #now set type
>>> atom.type = 1
>>> #Setting through constructor
>>> atom = Atom([23.0, 45.2, 34.2], 23, 1)
References
----------
`Creation of atoms <https://pyscal.readthedocs.io/en/latest/examples.html>`_.
)mydelimiter")
//-------------------------------------------------------
// Constructor, Destructor
//-------------------------------------------------------
.def(py::init < vector<double>, int , int >(), py::arg("pos")=vv, py::arg("id")=0, py::arg("type")=0)
//-------------------------------------------------------
// Basic Atom properties
//-------------------------------------------------------
.def_readwrite("pos", &Atom::pos, R"mydelimiter(
*List of floats of the type [x, y, z], default [0, 0, 0]*.
Position of the atom.
)mydelimiter")
.def_readwrite("id", &Atom::id, R"mydelimiter(
*int*.
Id of the atom.
)mydelimiter")
.def_readwrite("condition", &Atom::condition, R"mydelimiter(
*int*.
condition that specifies if an atom is included in the clustering algorithm or not.
Only atoms with the value of condition=1 will be used for clustering in
:func:`~pyscal.core.System.cluster_atoms`.
)mydelimiter")
.def_readwrite("mask", &Atom::mask, R"mydelimiter(
*bool*.
Mask variable for atom. If mask is true, the atom is ignored from calculations.
)mydelimiter")
.def_readwrite("loc", &Atom::loc, R"mydelimiter(
*int*.
indicates the position of the atom in the list of all atoms.
)mydelimiter")
.def_readwrite("type", &Atom::type, R"mydelimiter(
*int*.
int specifying type of the atom.
)mydelimiter")
.def_readwrite("ghost", &Atom::ghost, R"mydelimiter(
*int*.
int specifying ghost status of the atom.
)mydelimiter")
.def_readwrite("custom", &Atom::custom, R"mydelimiter(
*dict*.
dictionary specfying custom values for an atom. The module only stores the id, type and
position of the atom. If any extra values need to be stored, they can be stored in custom
using `atom.custom = {"velocity":12}`. :func:`~pyscal.core.System.read_inputfile` can also
read in extra atom information. By default, custom values are treated as string.
)mydelimiter")
//-------------------------------------------------------
// Neighbor related properties
//-------------------------------------------------------
.def_readwrite("neighbors",&Atom::neighbors, R"mydelimiter(
*List of ints*.
List of neighbors of the atom. The list contains indices of neighbor
atoms which indicate their position in the list of all atoms.
)mydelimiter")
.def_readwrite("neighbor_distance", &Atom::neighbordist, R"mydelimiter(
*List of floats*.
List of neighbor distances of the atom.
)mydelimiter")
.def_readwrite("coordination", &Atom::n_neighbors, R"mydelimiter(
*int*.
coordination number of the atom. Coordination will only be updated
after neighbors are calculated using :func:`~pyscal.core.System.find_neighbors`.
)mydelimiter")
.def_readwrite("neighbor_weights",&Atom::neighborweight, R"mydelimiter(
*List of floats*.
Used to weight the contribution of each neighbor atom towards the value of
Steinhardt's parameters. By default, each atom has a weight of 1 each. However,
if :func:`~pyscal.core.System.find_neighbors` is used with `method='voronoi'`,
each neighbor gets a weight proportional to the area shared between the neighboring
atom and host atom.
)mydelimiter")
.def_readwrite("cutoff", &Atom::cutoff, R"mydelimiter(
*double*.
cutoff used for finding neighbors for each atom.
)mydelimiter")
;
#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;
#else
m.attr("__version__") = "dev";
#endif
}