Example #1
0
 def __getBackendResults(self):
     """
     Private helper function to get the backend results.
     """
     # Setup the histogram data in python.
     self.__raw_histogram        = stdVectorCoordinateToNumpy2DArray(self.__backend.histogramBuffer())
     self.__bin_counters         = self.__backend.histogramBinCounts()
     self.__history_bin_counters = self.__backend.historyStepsHistogramBinCounts()
     self.__hstep_counts         = self.__backend.hstepCounts()
    def testStdVectorCoordinateToNumpy2DArray(self):
        """ Test the conversion from a std::vector<Coordinate> to a numpy array. """
        # Get a reference.
        ref_array = numpy.random.rand(6).reshape((2,3))

        # Setup the data to convert.
        cpp_vector = Backend.StdVectorCoordinate()
        cpp_vector.push_back(Backend.Coordinate(ref_array[0,0], ref_array[0,1], ref_array[0,2]))
        cpp_vector.push_back(Backend.Coordinate(ref_array[1,0], ref_array[1,1], ref_array[1,2]))

        # Convert.
        py_array = stdVectorCoordinateToNumpy2DArray(cpp_vector)

        # Check.
        diff = numpy.linalg.norm(ref_array - py_array)
        self.assertAlmostEqual( diff, 0.0, 10 )
    def testNumpy2DArrayToStdVectorCoordinate(self):
        """ Test the conversion of a Nx3 2D numpy array to a std::vector<Coordinate> representation. """
        nI = 12;
        nJ = 3;
        array = numpy.random.rand(nI,nJ)

        # Convert to c++
        cpp_vector = numpy2DArrayToStdVectorCoordinate(array)

        # Check the size.
        self.assertEqual(cpp_vector.size(), nI)

        # Check the type.
        self.assertTrue( isinstance(cpp_vector, Backend.StdVectorCoordinate) )

        # Convert back and check values.
        converted = stdVectorCoordinateToNumpy2DArray(cpp_vector)
        self.assertAlmostEqual(numpy.linalg.norm(array-converted), 0.0, 10)
    def testNumpy2DArrayToStdVectorCoordinate(self):
        """ Test the conversion of a Nx3 2D numpy array to a std::vector<Coordinate> representation. """
        nI = 12
        nJ = 3
        array = numpy.random.rand(nI, nJ)

        # Convert to c++
        cpp_vector = numpy2DArrayToStdVectorCoordinate(array)

        # Check the size.
        self.assertEqual(cpp_vector.size(), nI)

        # Check the type.
        self.assertTrue(isinstance(cpp_vector, Backend.StdVectorCoordinate))

        # Convert back and check values.
        converted = stdVectorCoordinateToNumpy2DArray(cpp_vector)
        self.assertAlmostEqual(numpy.linalg.norm(array - converted), 0.0, 10)
    def testStdVectorCoordinateToNumpy2DArray(self):
        """ Test the conversion from a std::vector<Coordinate> to a numpy array. """
        # Get a reference.
        ref_array = numpy.random.rand(6).reshape((2, 3))

        # Setup the data to convert.
        cpp_vector = Backend.StdVectorCoordinate()
        cpp_vector.push_back(
            Backend.Coordinate(ref_array[0, 0], ref_array[0, 1], ref_array[0,
                                                                           2]))
        cpp_vector.push_back(
            Backend.Coordinate(ref_array[1, 0], ref_array[1, 1], ref_array[1,
                                                                           2]))

        # Convert.
        py_array = stdVectorCoordinateToNumpy2DArray(cpp_vector)

        # Check.
        diff = numpy.linalg.norm(ref_array - py_array)
        self.assertAlmostEqual(diff, 0.0, 10)
Example #6
0
 def atomIDCoordinates(self):
     """
     Query for the coordinates per atom id.
     """
     return stdVectorCoordinateToNumpy2DArray(
         self._backend().atomIDCoordinates())
Example #7
0
 def atomIDCoordinates(self):
     """
     Query for the coordinates per atom id.
     """
     return stdVectorCoordinateToNumpy2DArray(self._backend().atomIDCoordinates())