Changeset 923ce2
- Timestamp:
- May 19, 2021, 7:06:29 PM (4 years ago)
- Branches:
- Candidate_v1.7.0, stable
- Children:
- 1e490ec
- Parents:
- ecc050
- git-author:
- Frederik Heber <frederik.heber@…> (06/21/20 21:29:52)
- git-committer:
- Frederik Heber <frederik.heber@…> (05/19/21 19:06:29)
- File:
-
- 1 edited
-
src/Python/export_numpy.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Python/export_numpy.cpp
recc050 r923ce2 37 37 #include<boost/bind.hpp> 38 38 #include<boost/function.hpp> 39 #include<boost/python /def.hpp>39 #include<boost/python.hpp> 40 40 #include<boost/python/numpy.hpp> 41 41 … … 55 55 { 56 56 p::tuple shape = p::make_tuple(num_atoms, 3); 57 np::dtype dtype = np::dtype::get_builtin< float>();57 np::dtype dtype = np::dtype::get_builtin<double>(); 58 58 np::ndarray array = np::zeros(shape, dtype); 59 59 return array; … … 63 63 { 64 64 unsigned int num_atoms = get_num_atoms(); 65 std::cout << num_atoms << std::endl;65 //std::cout << num_atoms << std::endl; 66 66 np::ndarray positions = allocate_ndarray(num_atoms); 67 67 … … 74 74 positions[ia][i] = _get_function(current)[i]; 75 75 ++ia; 76 ASSERT(ia <= num_atoms, "get_ positions() - more atoms selected than expected.");76 ASSERT(ia <= num_atoms, "get_ndarray() - more atoms selected than expected."); 77 77 } 78 78 … … 101 101 } 102 102 103 np::ndarray get_masses() 104 { 105 unsigned int num_atoms = get_num_atoms(); 106 //std::cout << num_atoms << std::endl; 107 p::tuple shape = p::make_tuple(num_atoms); 108 np::dtype dtype = np::dtype::get_builtin<double>(); 109 np::ndarray masses = np::zeros(shape, dtype); 110 111 unsigned int ia=0; 112 for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection(); 113 iter != World::getInstance().endAtomSelection(); 114 ++iter) { 115 const atom & current = *iter->second; 116 masses[ia] = current.getMass(); 117 ++ia; 118 ASSERT(ia <= num_atoms, "get_masses() - more atoms selected than expected."); 119 } 120 121 return masses; 122 } 123 103 124 void set_ndarray( 104 const np::ndarray & new_positions,125 const np::ndarray &_positions, 105 126 boost::function<void (atom &, const Vector &)> &_set_function) 106 127 { … … 108 129 109 130 // check whether shape of array is correct 110 ASSERT( new_positions.shape()[0]== num_atoms,111 "pyMoleCuilder::set_ positions() - numpy array has unexpected size.");131 ASSERT( _positions.shape(0) == num_atoms, 132 "pyMoleCuilder::set_ndarray() - numpy array has unexpected size."); 112 133 134 np::ndarray new_positions = _positions.copy(); 113 135 unsigned int ia=0; 114 136 Vector temp; … … 117 139 ++iter) { 118 140 atom ¤t = *iter->second; 119 for (unsigned int i=0;i<NDIM;++i) 141 for (unsigned int i=0;i<NDIM;++i) { 142 //std::cout << p::extract<char const *>(p::str(new_positions[ia][i])) << std::endl; 120 143 temp[i] = p::extract<double>(new_positions[ia][i]); 144 } 121 145 _set_function(current, temp); 122 146 ++ia; 123 ASSERT(ia <= num_atoms, "set_ positions() - more atoms selected than expected.");147 ASSERT(ia <= num_atoms, "set_ndarray() - more atoms selected than expected."); 124 148 } 125 149 } … … 151 175 p::def("get_velocities", get_velocities); 152 176 p::def("get_forces", get_forces); 177 p::def("get_masses", get_masses); 153 178 p::def("set_positions", set_positions, p::args("position")); 154 179 p::def("set_velocities", set_velocities, p::args("velocity"));
Note:
See TracChangeset
for help on using the changeset viewer.
