diff --git a/src/USER-PTM/ptm_alloy_types.cpp b/src/USER-PTM/ptm_alloy_types.cpp
index e14d06db999d99268944e64850ab2d2a54c8ab91..151de3e5b852438e93c977154d80c8da0b9e7199 100644
--- a/src/USER-PTM/ptm_alloy_types.cpp
+++ b/src/USER-PTM/ptm_alloy_types.cpp
@@ -2,6 +2,7 @@
 #include "ptm_constants.h"
 #include "ptm_initialize_data.h"
 
+namespace ptm {
 
 #define NUM_ALLOY_TYPES 3
 static uint32_t typedata[NUM_ALLOY_TYPES][3] = {
@@ -99,3 +100,5 @@ int32_t find_alloy_type(const refdata_t* ref, int8_t* mapping, int32_t* numbers)
 	return PTM_ALLOY_NONE;
 }
 
+}
+
diff --git a/src/USER-PTM/ptm_alloy_types.h b/src/USER-PTM/ptm_alloy_types.h
index 6ea6ed1b8aaa8b7b45f0b5b744b085bb16d3f802..559e0a749048651dfba7d9036e9b31b6b3281503 100644
--- a/src/USER-PTM/ptm_alloy_types.h
+++ b/src/USER-PTM/ptm_alloy_types.h
@@ -3,7 +3,11 @@
 
 #include "ptm_initialize_data.h"
 
+namespace ptm {
+
 int32_t find_alloy_type(const refdata_t* ref, int8_t* mapping, int32_t* numbers);
 
+}
+
 #endif
 
diff --git a/src/USER-PTM/ptm_canonical_coloured.cpp b/src/USER-PTM/ptm_canonical_coloured.cpp
index 551f52d7e4b985bccff16a1ec0feaf34ef734dc7..ade8f23b15f7cbb3023de9acba4afef8f17d9dca 100644
--- a/src/USER-PTM/ptm_canonical_coloured.cpp
+++ b/src/USER-PTM/ptm_canonical_coloured.cpp
@@ -4,6 +4,7 @@
 #include "ptm_graph_tools.h"
 #include "ptm_constants.h"
 
+namespace ptm {
 
 static bool weinberg_coloured(int num_nodes, int num_edges, int8_t common[PTM_MAX_NBRS][PTM_MAX_NBRS], int8_t* colours, int8_t* best_code, int8_t* canonical_labelling, int a, int b)
 {
@@ -165,3 +166,5 @@ int canonical_form_coloured(int num_facets, int8_t facets[][3], int num_nodes, i
 	return PTM_NO_ERROR;
 }
 
+}
+
diff --git a/src/USER-PTM/ptm_canonical_coloured.h b/src/USER-PTM/ptm_canonical_coloured.h
index e71bb08bfc605752fd559d0d68ea657ec55819f9..f8e2a7af5db08031ccafacfdc0d9244fb9e3fbdb 100644
--- a/src/USER-PTM/ptm_canonical_coloured.h
+++ b/src/USER-PTM/ptm_canonical_coloured.h
@@ -3,7 +3,10 @@
 
 #include <stdint.h>
 
+namespace ptm {
+
 int canonical_form_coloured(int num_facets, int8_t facets[][3], int num_nodes, int8_t* degree, int8_t* colours, int8_t* canonical_labelling, int8_t* best_code, uint64_t* p_hash);
+}
 
 #endif
 
diff --git a/src/USER-PTM/ptm_convex_hull_incremental.cpp b/src/USER-PTM/ptm_convex_hull_incremental.cpp
index c996b17b5886785bfc148614b1afa7d6508af1ee..7c79fd371a532f1c20b9d21767b011d60e4d0849 100644
--- a/src/USER-PTM/ptm_convex_hull_incremental.cpp
+++ b/src/USER-PTM/ptm_convex_hull_incremental.cpp
@@ -6,6 +6,7 @@
 #include "ptm_convex_hull_incremental.h"
 #include "ptm_constants.h"
 
+namespace ptm {
 
 #define VISIBLE 1
 #define INVISIBLE 2
@@ -361,3 +362,5 @@ int get_convex_hull(int num_points, const double (*points)[3], convexhull_t* ch,
 	return ret;
 }
 
+}
+
diff --git a/src/USER-PTM/ptm_convex_hull_incremental.h b/src/USER-PTM/ptm_convex_hull_incremental.h
index 563a0c436a0b612d7dd519790a88ecf05fd71447..6474723907086652d084d8914a63fbea799650e2 100644
--- a/src/USER-PTM/ptm_convex_hull_incremental.h
+++ b/src/USER-PTM/ptm_convex_hull_incremental.h
@@ -6,6 +6,7 @@
 #include <stdbool.h>
 #include "ptm_constants.h"
 
+namespace ptm {
 
 typedef struct
 {
@@ -23,5 +24,7 @@ typedef struct
 void add_facet(const double (*points)[3], int a, int b, int c, int8_t* facet, double* plane_normal, double* barycentre);
 int get_convex_hull(int num_points, const double (*points)[3], convexhull_t* ch, int8_t simplex[][3]);
 
+}
+
 #endif
 
diff --git a/src/USER-PTM/ptm_deformation_gradient.cpp b/src/USER-PTM/ptm_deformation_gradient.cpp
index d566d5ca1198f0425f855283feddefbcc5cadb24..fc851920a6854f8dfeeb7ae59215567644ba111c 100644
--- a/src/USER-PTM/ptm_deformation_gradient.cpp
+++ b/src/USER-PTM/ptm_deformation_gradient.cpp
@@ -1,5 +1,6 @@
 #include "ptm_deformation_gradient.h"
 
+namespace ptm {
 
 void calculate_deformation_gradient(int num_points, const double (*ideal_points)[3], int8_t* mapping, double (*normalized)[3], const double (*penrose)[3], double* F, double* res)
 {
@@ -35,3 +36,5 @@ void calculate_deformation_gradient(int num_points, const double (*ideal_points)
 	}
 }
 
+}
+
diff --git a/src/USER-PTM/ptm_deformation_gradient.h b/src/USER-PTM/ptm_deformation_gradient.h
index 7decab4b76144400b084dbac493a59bca6855557..32836da44d48dfa8791bbb56f43a8c29e4ffc1f2 100644
--- a/src/USER-PTM/ptm_deformation_gradient.h
+++ b/src/USER-PTM/ptm_deformation_gradient.h
@@ -4,6 +4,8 @@
 #include <stdint.h>
 #include "ptm_constants.h"
 
+namespace ptm {
+
 void calculate_deformation_gradient(int num_points, const double (*ideal_points)[3], int8_t* mapping, double (*normalized)[3], const double (*penrose)[3], double* F, double* res);
 
 //sc
@@ -137,6 +139,8 @@ const double penrose_dhex[PTM_NUM_POINTS_DHEX][3] = {
 					{          0,  2 * kdcub,  -2 * kdcub },
 					{  2 * kdcub,          0,  -2 * kdcub },
 				};
+}
+
 #endif
 
 
diff --git a/src/USER-PTM/ptm_fundamental_mappings.h b/src/USER-PTM/ptm_fundamental_mappings.h
index 3dd7c39cbb30f0bd494a7376bb93be553c7b876e..35fae7f08834cd303065591e0a54ad83f0480d93 100644
--- a/src/USER-PTM/ptm_fundamental_mappings.h
+++ b/src/USER-PTM/ptm_fundamental_mappings.h
@@ -3,6 +3,8 @@
 
 #include <stdint.h>
 
+namespace ptm {
+
 #define NUM_CUBIC_MAPPINGS 24
 #define NUM_ICO_MAPPINGS 60
 #define NUM_HEX_MAPPINGS 6
@@ -175,6 +177,7 @@ const int8_t mapping_dhex[NUM_DHEX_MAPPINGS][PTM_MAX_POINTS] = {
 					{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
 					{0, 1, 3, 4, 2, 6, 7, 5, 11, 13, 12, 14, 16, 15, 8, 9, 10},
 					{0, 1, 4, 2, 3, 7, 5, 6, 14, 15, 16, 8, 10, 9, 11, 13, 12}	};
+}
 
 #endif
 
diff --git a/src/USER-PTM/ptm_graph_data.cpp b/src/USER-PTM/ptm_graph_data.cpp
index a591dbf993a8af5affaa6740b7d440ea60fe81b2..a742c8b3398c7c7a7eeb5862d8507756043fb078 100644
--- a/src/USER-PTM/ptm_graph_data.cpp
+++ b/src/USER-PTM/ptm_graph_data.cpp
@@ -1,6 +1,8 @@
 #include "ptm_graph_data.h"
 
 
+namespace ptm {
+
 int8_t automorphisms[65][17] = {
 	{  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16},
 	{  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, -1, -1, -1, -1},
@@ -2057,3 +2059,5 @@ graph_t graphs_dhex[NUM_DHEX_GRAPHS] = {
 
 };
 
+}
+
diff --git a/src/USER-PTM/ptm_graph_data.h b/src/USER-PTM/ptm_graph_data.h
index 11f46a471fc2a9c347d6d580159656e99a863a56..251c82d2f5b2381a19188709bca6ae6cbc87ad4d 100644
--- a/src/USER-PTM/ptm_graph_data.h
+++ b/src/USER-PTM/ptm_graph_data.h
@@ -4,6 +4,7 @@
 #include <stdint.h>
 #include "ptm_constants.h"
 
+namespace ptm {
 
 typedef struct
 {
@@ -33,5 +34,7 @@ extern graph_t graphs_bcc[NUM_BCC_GRAPHS];
 extern graph_t graphs_dcub[NUM_DCUB_GRAPHS];
 extern graph_t graphs_dhex[NUM_DHEX_GRAPHS];
 
+}
+
 #endif
 
diff --git a/src/USER-PTM/ptm_graph_tools.cpp b/src/USER-PTM/ptm_graph_tools.cpp
index 89d07fc87a39439660db05b7b6d2be7b4798acbc..f6fd34d097a19167896615f442ec818adc650fe0 100644
--- a/src/USER-PTM/ptm_graph_tools.cpp
+++ b/src/USER-PTM/ptm_graph_tools.cpp
@@ -4,6 +4,8 @@
 #include "ptm_constants.h"
 
 
+namespace ptm {
+
 bool build_facet_map(int num_facets, int8_t facets[][3], int8_t common[PTM_MAX_NBRS][PTM_MAX_NBRS])
 {
 	memset(common, -1, sizeof(int8_t) * PTM_MAX_NBRS * PTM_MAX_NBRS);
@@ -50,3 +52,5 @@ int graph_degree(int num_facets, int8_t facets[][3], int num_nodes, int8_t* degr
 	return max_degree;
 }
 
+}
+
diff --git a/src/USER-PTM/ptm_graph_tools.h b/src/USER-PTM/ptm_graph_tools.h
index 78934e87c1d21a7a1ee38fc1be6cc80d38db2da3..7befad526b4435253742372ccad85d8355005619 100644
--- a/src/USER-PTM/ptm_graph_tools.h
+++ b/src/USER-PTM/ptm_graph_tools.h
@@ -4,8 +4,12 @@
 #include <stdint.h>
 #include "ptm_constants.h"
 
+namespace ptm {
+
 bool build_facet_map(int num_facets, int8_t facets[][3], int8_t common[PTM_MAX_NBRS][PTM_MAX_NBRS]);
 int graph_degree(int num_facets, int8_t facets[][3], int num_nodes, int8_t* degree);
 
+}
+
 #endif
 
diff --git a/src/USER-PTM/ptm_index.cpp b/src/USER-PTM/ptm_index.cpp
index 7b6618848e18989efc2040f8507034cd6c2537b9..24998dadd0a440048740cd2ff30fdbf9eb244e57 100644
--- a/src/USER-PTM/ptm_index.cpp
+++ b/src/USER-PTM/ptm_index.cpp
@@ -36,13 +36,13 @@ static double calculate_lattice_constant(int type, double interatomic_distance)
 
 static int rotate_into_fundamental_zone(int type, double* q)
 {
-	if (type == PTM_MATCH_SC)	return rotate_quaternion_into_cubic_fundamental_zone(q);
-	if (type == PTM_MATCH_FCC)	return rotate_quaternion_into_cubic_fundamental_zone(q);
-	if (type == PTM_MATCH_BCC)	return rotate_quaternion_into_cubic_fundamental_zone(q);
-	if (type == PTM_MATCH_ICO)	return rotate_quaternion_into_icosahedral_fundamental_zone(q);
-	if (type == PTM_MATCH_HCP)	return rotate_quaternion_into_hcp_fundamental_zone(q);
-	if (type == PTM_MATCH_DCUB)	return rotate_quaternion_into_diamond_cubic_fundamental_zone(q);
-	if (type == PTM_MATCH_DHEX)	return rotate_quaternion_into_diamond_hexagonal_fundamental_zone(q);
+	if (type == PTM_MATCH_SC)	return ptm::rotate_quaternion_into_cubic_fundamental_zone(q);
+	if (type == PTM_MATCH_FCC)	return ptm::rotate_quaternion_into_cubic_fundamental_zone(q);
+	if (type == PTM_MATCH_BCC)	return ptm::rotate_quaternion_into_cubic_fundamental_zone(q);
+	if (type == PTM_MATCH_ICO)	return ptm::rotate_quaternion_into_icosahedral_fundamental_zone(q);
+	if (type == PTM_MATCH_HCP)	return ptm::rotate_quaternion_into_hcp_fundamental_zone(q);
+	if (type == PTM_MATCH_DCUB)	return ptm::rotate_quaternion_into_diamond_cubic_fundamental_zone(q);
+	if (type == PTM_MATCH_DHEX)	return ptm::rotate_quaternion_into_diamond_hexagonal_fundamental_zone(q);
 	return -1;
 }
 
@@ -52,8 +52,8 @@ static void order_points(ptm_local_handle_t local_handle, int num_points, double
 	if (topological_ordering)
 	{
 		double normalized_points[PTM_MAX_INPUT_POINTS][3];
-		normalize_vertices(num_points, unpermuted_points, normalized_points);
-		int ret = calculate_neighbour_ordering((void*)local_handle, num_points, (const double (*)[3])normalized_points, ordering);
+		ptm::normalize_vertices(num_points, unpermuted_points, normalized_points);
+		int ret = ptm::calculate_neighbour_ordering((void*)local_handle, num_points, (const double (*)[3])normalized_points, ordering);
 		if (ret != 0)
 			topological_ordering = false;
 	}
@@ -71,7 +71,7 @@ static void order_points(ptm_local_handle_t local_handle, int num_points, double
 	}
 }
 
-static void output_data(result_t* res, int num_points, int32_t* unpermuted_numbers, double (*points)[3], int32_t* numbers, int8_t* ordering,
+static void output_data(ptm::result_t* res, int num_points, int32_t* unpermuted_numbers, double (*points)[3], int32_t* numbers, int8_t* ordering,
 			int32_t* p_type, int32_t* p_alloy_type, double* p_scale, double* p_rmsd, double* q, double* F, double* F_res,
 			double* U, double* P, int8_t* mapping, double* p_interatomic_distance, double* p_lattice_constant)
 {
@@ -82,13 +82,13 @@ static void output_data(result_t* res, int num_points, int32_t* unpermuted_numbe
 	if (mapping != NULL)
 		memset(mapping, -1, num_points * sizeof(int8_t));
 
-	const refdata_t* ref = res->ref_struct;
+	const ptm::refdata_t* ref = res->ref_struct;
 	if (ref == NULL)
 		return;
 
 	*p_type = ref->type;
 	if (p_alloy_type != NULL && unpermuted_numbers != NULL)
-		*p_alloy_type = find_alloy_type(ref, res->mapping, numbers);
+		*p_alloy_type = ptm::find_alloy_type(ref, res->mapping, numbers);
 
 	int bi = rotate_into_fundamental_zone(ref->type, res->q);
 	int8_t temp[PTM_MAX_POINTS];
@@ -101,17 +101,17 @@ static void output_data(result_t* res, int num_points, int32_t* unpermuted_numbe
 	{
 		double scaled_points[PTM_MAX_INPUT_POINTS][3];
 
-		subtract_barycentre(ref->num_nbrs + 1, points, scaled_points);
+		ptm::subtract_barycentre(ref->num_nbrs + 1, points, scaled_points);
 		for (int i = 0;i<ref->num_nbrs + 1;i++)
 		{
 			scaled_points[i][0] *= res->scale;
 			scaled_points[i][1] *= res->scale;
 			scaled_points[i][2] *= res->scale;
 		}
-		calculate_deformation_gradient(ref->num_nbrs + 1, ref->points, res->mapping, scaled_points, ref->penrose, F, F_res);
+		ptm::calculate_deformation_gradient(ref->num_nbrs + 1, ref->points, res->mapping, scaled_points, ref->penrose, F, F_res);
 
 		if (P != NULL && U != NULL)
-			polar_decomposition_3x3(F, false, U, P);
+			ptm::polar_decomposition_3x3(F, false, U, P);
 	}
 
 	if (mapping != NULL)
@@ -156,7 +156,7 @@ int ptm_index(	ptm_local_handle_t local_handle, int32_t flags,
 		assert(num_points >= PTM_NUM_POINTS_DCUB);
 
 	int ret = 0;
-	result_t res;
+	ptm::result_t res;
 	res.ref_struct = NULL;
 	res.rmsd = INFINITY;
 
@@ -168,32 +168,32 @@ int ptm_index(	ptm_local_handle_t local_handle, int32_t flags,
 	double dpoints[PTM_MAX_POINTS][3];
 	int32_t dnumbers[PTM_MAX_POINTS];
 
-	convexhull_t ch;
+	ptm::convexhull_t ch;
 	double ch_points[PTM_MAX_INPUT_POINTS][3];
 
 	if (flags & (PTM_CHECK_SC | PTM_CHECK_FCC | PTM_CHECK_HCP | PTM_CHECK_ICO | PTM_CHECK_BCC))
 	{
 		int num_lpoints = std::min(std::min(PTM_MAX_POINTS, 20), num_points);
 		order_points(local_handle, num_lpoints, unpermuted_points, unpermuted_numbers, topological_ordering, ordering, points, numbers);
-		normalize_vertices(num_lpoints, points, ch_points);
+		ptm::normalize_vertices(num_lpoints, points, ch_points);
 		ch.ok = false;
 
 		if (flags & PTM_CHECK_SC)
-			ret = match_general(&structure_sc, ch_points, points, &ch, &res);
+			ret = match_general(&ptm::structure_sc, ch_points, points, &ch, &res);
 
 		if (flags & (PTM_CHECK_FCC | PTM_CHECK_HCP | PTM_CHECK_ICO))
 			ret = match_fcc_hcp_ico(ch_points, points, flags, &ch, &res);
 
 		if (flags & PTM_CHECK_BCC)
-			ret = match_general(&structure_bcc, ch_points, points, &ch, &res);
+			ret = match_general(&ptm::structure_bcc, ch_points, points, &ch, &res);
 	}
 
 	if (flags & (PTM_CHECK_DCUB | PTM_CHECK_DHEX))
 	{
-		ret = calculate_diamond_neighbour_ordering(num_points, unpermuted_points, unpermuted_numbers, dordering, dpoints, dnumbers);
+		ret = ptm::calculate_diamond_neighbour_ordering(num_points, unpermuted_points, unpermuted_numbers, dordering, dpoints, dnumbers);
 		if (ret == 0)
 		{
-			normalize_vertices(PTM_NUM_NBRS_DCUB + 1, dpoints, ch_points);
+			ptm::normalize_vertices(PTM_NUM_NBRS_DCUB + 1, dpoints, ch_points);
 			ch.ok = false;
 
 			ret = match_dcub_dhex(ch_points, dpoints, flags, &ch, &res);
diff --git a/src/USER-PTM/ptm_initialize_data.cpp b/src/USER-PTM/ptm_initialize_data.cpp
index 6157ff862f92e2c2bf69a9ad7c26e97d0d926096..8d96e2a2b77b877cdc020213cc98dd5934596824 100644
--- a/src/USER-PTM/ptm_initialize_data.cpp
+++ b/src/USER-PTM/ptm_initialize_data.cpp
@@ -14,20 +14,20 @@ static void make_facets_clockwise(int num_facets, int8_t (*facets)[3], const dou
 	double origin[3] = {0, 0, 0};
 
 	for (int i = 0;i<num_facets;i++)
-		add_facet(points, facets[i][0], facets[i][1], facets[i][2], facets[i], plane_normal, origin);
+		ptm::add_facet(points, facets[i][0], facets[i][1], facets[i][2], facets[i], plane_normal, origin);
 }
 
-static int initialize_graphs(const refdata_t* s, int8_t* colours)
+static int initialize_graphs(const ptm::refdata_t* s, int8_t* colours)
 {
 	for (int i = 0;i<s->num_graphs;i++)
 	{
 		int8_t code[2 * PTM_MAX_EDGES];
 		int8_t degree[PTM_MAX_NBRS];
-		int _max_degree = graph_degree(s->num_facets, s->graphs[i].facets, s->num_nbrs, degree);
+		int _max_degree = ptm::graph_degree(s->num_facets, s->graphs[i].facets, s->num_nbrs, degree);
 		assert(_max_degree <= s->max_degree);
 
 		make_facets_clockwise(s->num_facets, s->graphs[i].facets, &s->points[1]);
-		int ret = canonical_form_coloured(s->num_facets, s->graphs[i].facets, s->num_nbrs, degree, colours, s->graphs[i].canonical_labelling, (int8_t*)&code[0], &s->graphs[i].hash);
+		int ret = ptm::canonical_form_coloured(s->num_facets, s->graphs[i].facets, s->num_nbrs, degree, colours, s->graphs[i].canonical_labelling, (int8_t*)&code[0], &s->graphs[i].hash);
 		if (ret != 0)
 			return ret;		
 	}
@@ -44,13 +44,13 @@ int ptm_initialize_global()
 	int8_t colours[PTM_MAX_POINTS] = {0};
 	int8_t dcolours[PTM_MAX_POINTS] = {1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-	int ret = initialize_graphs(&structure_sc, colours);
-	ret |= initialize_graphs(&structure_fcc, colours);
-	ret |= initialize_graphs(&structure_hcp, colours);
-	ret |= initialize_graphs(&structure_ico, colours);
-	ret |= initialize_graphs(&structure_bcc, colours);
-	ret |= initialize_graphs(&structure_dcub, dcolours);
-	ret |= initialize_graphs(&structure_dhex, dcolours);
+	int ret = initialize_graphs(&ptm::structure_sc, colours);
+	ret |= initialize_graphs(&ptm::structure_fcc, colours);
+	ret |= initialize_graphs(&ptm::structure_hcp, colours);
+	ret |= initialize_graphs(&ptm::structure_ico, colours);
+	ret |= initialize_graphs(&ptm::structure_bcc, colours);
+	ret |= initialize_graphs(&ptm::structure_dcub, dcolours);
+	ret |= initialize_graphs(&ptm::structure_dhex, dcolours);
 
 	if (ret == PTM_NO_ERROR)
 		ptm_initialized = true;
@@ -61,11 +61,11 @@ int ptm_initialize_global()
 ptm_local_handle_t ptm_initialize_local()
 {
 	assert(ptm_initialized);
-	return (ptm_local_handle_t)voronoi_initialize_local();
+	return (ptm_local_handle_t)ptm::voronoi_initialize_local();
 }
 
 void ptm_uninitialize_local(ptm_local_handle_t ptr)
 {
-	voronoi_uninitialize_local(ptr);
+	ptm::voronoi_uninitialize_local(ptr);
 }
 
diff --git a/src/USER-PTM/ptm_initialize_data.h b/src/USER-PTM/ptm_initialize_data.h
index f381dd864b34637e926b3ce5e3c4df5fb4044b7e..5374fbf7d0212ede7278c635e654d258680d650e 100644
--- a/src/USER-PTM/ptm_initialize_data.h
+++ b/src/USER-PTM/ptm_initialize_data.h
@@ -11,6 +11,8 @@
 #include "ptm_convex_hull_incremental.h"
 
 
+namespace ptm {
+
 typedef struct
 {
 	int type;
@@ -35,6 +37,7 @@ const refdata_t structure_bcc =  { PTM_MATCH_BCC,  14, 24, 8, NUM_BCC_GRAPHS,  N
 const refdata_t structure_dcub = { PTM_MATCH_DCUB, 16, 28, 8, NUM_DCUB_GRAPHS, NUM_DCUB_MAPPINGS,  graphs_dcub, ptm_template_dcub, penrose_dcub, mapping_dcub };
 const refdata_t structure_dhex = { PTM_MATCH_DHEX, 16, 28, 8, NUM_DHEX_GRAPHS, NUM_DHEX_MAPPINGS,  graphs_dhex, ptm_template_dhex, penrose_dhex, mapping_dhex };
 
+}
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/src/USER-PTM/ptm_neighbour_ordering.cpp b/src/USER-PTM/ptm_neighbour_ordering.cpp
index 6b5ac9601a568e4634d63d87321a3f9529cf1b57..c77a779c6885fdaf435f955f0a156b35e6484134 100644
--- a/src/USER-PTM/ptm_neighbour_ordering.cpp
+++ b/src/USER-PTM/ptm_neighbour_ordering.cpp
@@ -5,9 +5,9 @@
 #include <algorithm>
 #include "ptm_constants.h"
 #include "ptm_voronoi_cell.h"
-using namespace voro;
 
 
+namespace ptm {
 
 typedef struct
 {
@@ -31,7 +31,7 @@ static bool sorthelper_compare(sorthelper_t const& a, sorthelper_t const& b)
 }
 
 //todo: change voronoi code to return errors rather than exiting
-static int calculate_voronoi_face_areas(int num_points, const double (*_points)[3], double* normsq, double max_norm, voronoicell_neighbor* v, std::vector<int>& nbr_indices, std::vector<double>& face_areas)
+static int calculate_voronoi_face_areas(int num_points, const double (*_points)[3], double* normsq, double max_norm, ptm_voro::voronoicell_neighbor* v, std::vector<int>& nbr_indices, std::vector<double>& face_areas)
 {
 	const double k = 1000 * max_norm;	//todo: reduce this constant
 	v->init(-k,k,-k,k,-k,k);
@@ -53,7 +53,7 @@ int calculate_neighbour_ordering(void* _voronoi_handle, int num_points, const do
 {
 	assert(num_points <= PTM_MAX_INPUT_POINTS);
 
-	voronoicell_neighbor* voronoi_handle = (voronoicell_neighbor*)_voronoi_handle;
+	ptm_voro::voronoicell_neighbor* voronoi_handle = (ptm_voro::voronoicell_neighbor*)_voronoi_handle;
 
 	double max_norm = 0;
 	double points[PTM_MAX_INPUT_POINTS][3];
@@ -116,13 +116,13 @@ int calculate_neighbour_ordering(void* _voronoi_handle, int num_points, const do
 
 void* voronoi_initialize_local()
 {
-	voronoicell_neighbor* ptr = new voronoicell_neighbor;
+	ptm_voro::voronoicell_neighbor* ptr = new ptm_voro::voronoicell_neighbor;
 	return (void*)ptr;
 }
 
 void voronoi_uninitialize_local(void* _ptr)
 {
-	voronoicell_neighbor* ptr = (voronoicell_neighbor*)_ptr;
+	ptm_voro::voronoicell_neighbor* ptr = (ptm_voro::voronoicell_neighbor*)_ptr;
 	delete ptr;
 }
 
@@ -201,3 +201,5 @@ int calculate_diamond_neighbour_ordering(	int num_points, double (*unpermuted_po
 	return 0;
 }
 
+}
+
diff --git a/src/USER-PTM/ptm_neighbour_ordering.h b/src/USER-PTM/ptm_neighbour_ordering.h
index ce4dfca2c00a05e701e5dc6e35dbc03bc83e667c..e43ced9fd513c21bfddbe24a71c964f5e160dcd3 100644
--- a/src/USER-PTM/ptm_neighbour_ordering.h
+++ b/src/USER-PTM/ptm_neighbour_ordering.h
@@ -1,6 +1,8 @@
 #ifndef PTM_NEIGHBOUR_ORDERING_H
 #define PTM_NEIGHBOUR_ORDERING_H
 
+namespace ptm {
+
 int calculate_neighbour_ordering(void* voronoi_handle, int num_points, const double (*_points)[3], int8_t* ordering);
 
 int calculate_diamond_neighbour_ordering(	int num_points, double (*unpermuted_points)[3], int32_t* unpermuted_numbers,
@@ -9,5 +11,7 @@ int calculate_diamond_neighbour_ordering(	int num_points, double (*unpermuted_po
 void* voronoi_initialize_local();
 void voronoi_uninitialize_local(void* ptr);
 
+}
+
 #endif
 
diff --git a/src/USER-PTM/ptm_normalize_vertices.cpp b/src/USER-PTM/ptm_normalize_vertices.cpp
index 61dca5006f6d8c8a47f96cc65e8e541d89fafe5e..22e3c1e6706cbb7f3b50811b5d29ac7ac826cfac 100644
--- a/src/USER-PTM/ptm_normalize_vertices.cpp
+++ b/src/USER-PTM/ptm_normalize_vertices.cpp
@@ -1,5 +1,6 @@
 #include <cmath>
 
+namespace ptm {
 
 void subtract_barycentre(int num, double (*points)[3], double (*normalized)[3])
 {
@@ -53,3 +54,5 @@ double normalize_vertices(int num, double (*points)[3], double (*normalized)[3])
 	return scale;
 }
 
+}
+
diff --git a/src/USER-PTM/ptm_normalize_vertices.h b/src/USER-PTM/ptm_normalize_vertices.h
index 2c7b7227529659c6b8ecc7f02efefccb69224c66..dc93db94a3ae97372f0343f1331a7e82ae618a54 100644
--- a/src/USER-PTM/ptm_normalize_vertices.h
+++ b/src/USER-PTM/ptm_normalize_vertices.h
@@ -1,8 +1,12 @@
 #ifndef PTM_NORMALIZE_VERTICES_H
 #define PTM_NORMALIZE_VERTICES_H
 
+namespace ptm {
+
 void subtract_barycentre(int num, double (*points)[3], double (*normalized)[3]);
 double normalize_vertices(int num, double (*points)[3], double (*normalized)[3]);
 
+}
+
 #endif
 
diff --git a/src/USER-PTM/ptm_polar.cpp b/src/USER-PTM/ptm_polar.cpp
index 9089b327b91da9a2eb9df80a9f34b628eae1443e..fa199ca6567a87affc0a75ca5e2981454a419c4f 100644
--- a/src/USER-PTM/ptm_polar.cpp
+++ b/src/USER-PTM/ptm_polar.cpp
@@ -91,6 +91,8 @@
 #include "ptm_quat.h"
 
 
+namespace ptm {
+
 static void matmul_3x3(double* A, double* x, double* b)
 {
 	b[0] = A[0] * x[0] + A[1] * x[3] + A[2] * x[6];
@@ -335,3 +337,5 @@ int FastCalcRMSDAndRotation(double *A, double E0, double *p_nrmsdsq, double *q,
 	return 0;
 }
 
+}
+
diff --git a/src/USER-PTM/ptm_polar.h b/src/USER-PTM/ptm_polar.h
index d5aa3d9540646410273d52d20bc3e33962b977d2..15d1f185b77749bf2207a3d44f7382e57b38f057 100644
--- a/src/USER-PTM/ptm_polar.h
+++ b/src/USER-PTM/ptm_polar.h
@@ -4,9 +4,13 @@
 #include <stdint.h>
 #include <stdbool.h>
 
+namespace ptm {
+
 int polar_decomposition_3x3(double* _A, bool right_sided, double* U, double* P);
 void InnerProduct(double *A, int num, const double (*coords1)[3], double (*coords2)[3], int8_t* permutation);
 int FastCalcRMSDAndRotation(double *A, double E0, double *p_nrmsdsq, double *q, double* U);
 
+}
+
 #endif
 
diff --git a/src/USER-PTM/ptm_quat.cpp b/src/USER-PTM/ptm_quat.cpp
index f55aff3d2b923d7ced41a49ee46140a13ce8613d..376cc749015ead94a7f1ce79a10438e0c1829e49 100644
--- a/src/USER-PTM/ptm_quat.cpp
+++ b/src/USER-PTM/ptm_quat.cpp
@@ -3,6 +3,8 @@
 #include <cfloat>
 
 
+namespace ptm {
+
 #define SIGN(x) (x >= 0 ? 1 : -1)
 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
 #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
@@ -394,3 +396,5 @@ double quat_disorientation_icosahedral(double* q0, double* q1)
 	return acos(quat_quick_disorientation_icosahedral(q0, q1));
 }
 
+}
+
diff --git a/src/USER-PTM/ptm_quat.h b/src/USER-PTM/ptm_quat.h
index 381c3ce876d606bc7a8ee868702245d46b20cf70..74caa2c62c3776eee0e3953438fa6ff2da6794f8 100644
--- a/src/USER-PTM/ptm_quat.h
+++ b/src/USER-PTM/ptm_quat.h
@@ -1,6 +1,8 @@
 #ifndef PTM_QUAT_H
 #define PTM_QUAT_H
 
+namespace ptm {
+
 int rotate_quaternion_into_cubic_fundamental_zone(double* q);
 int rotate_quaternion_into_diamond_cubic_fundamental_zone(double* q);
 int rotate_quaternion_into_icosahedral_fundamental_zone(double* q);
@@ -25,8 +27,7 @@ double quat_disorientation_diamond_hexagonal(double* q0, double* q1);
 double quat_quick_disorientation_icosahedral(double* q0, double* q1);
 double quat_disorientation_icosahedral(double* q0, double* q1);
 
-#endif
-
-
+}
 
+#endif
 
diff --git a/src/USER-PTM/ptm_structure_matcher.cpp b/src/USER-PTM/ptm_structure_matcher.cpp
index 7eb0a4414329b34f6ab742c3facde75fd09e049e..a86b3670cef6818da8386f5d250b721d9a75752d 100644
--- a/src/USER-PTM/ptm_structure_matcher.cpp
+++ b/src/USER-PTM/ptm_structure_matcher.cpp
@@ -15,6 +15,8 @@
 #include "ptm_constants.h"
 
 
+namespace ptm {
+
 static double calc_rmsd(int num_points, const double (*ideal_points)[3], double (*normalized)[3], int8_t* mapping,
 			double G1, double G2, double E0, double* q, double* p_scale)
 {
@@ -292,3 +294,5 @@ int match_dcub_dhex(double (*ch_points)[3], double (*points)[3], int32_t flags,
 	return PTM_NO_ERROR;
 }
 
+}
+
diff --git a/src/USER-PTM/ptm_structure_matcher.h b/src/USER-PTM/ptm_structure_matcher.h
index 4b6f969597cee7dc8a787ef52d24c17a80a4dec6..ffaed78e82dceae4ab29b52dbae77b8f936c7e33 100644
--- a/src/USER-PTM/ptm_structure_matcher.h
+++ b/src/USER-PTM/ptm_structure_matcher.h
@@ -4,6 +4,9 @@
 #include "ptm_initialize_data.h"
 #include "ptm_constants.h"
 
+
+namespace ptm {
+
 typedef struct
 {
 	double rmsd;
@@ -17,5 +20,7 @@ int match_general(const refdata_t* s, double (*ch_points)[3], double (*points)[3
 int match_fcc_hcp_ico(double (*ch_points)[3], double (*points)[3], int32_t flags, convexhull_t* ch, result_t* res);
 int match_dcub_dhex(double (*ch_points)[3], double (*points)[3], int32_t flags, convexhull_t* ch, result_t* res);
 
+}
+
 #endif
 
diff --git a/src/USER-PTM/ptm_voronoi_cell.cpp b/src/USER-PTM/ptm_voronoi_cell.cpp
index 6503ea16c6d9c9d9de81debdbb43e8658ad9bc28..ffd7a95ea2cb62850501e6cc702d649d5fc36eea 100644
--- a/src/USER-PTM/ptm_voronoi_cell.cpp
+++ b/src/USER-PTM/ptm_voronoi_cell.cpp
@@ -15,7 +15,7 @@
 #include "ptm_voronoi_config.h"
 #include "ptm_voronoi_cell.h"
 
-namespace voro {
+namespace ptm_voro {
 
 inline void voro_fatal_error(const char *p,int status) {
 	fprintf(stderr,"voro++: %s\n",p);
diff --git a/src/USER-PTM/ptm_voronoi_cell.h b/src/USER-PTM/ptm_voronoi_cell.h
index 80a0501b3cd7146749bb02643977b4353771d2a6..e0284bc56fa6c7a65c2a467e2283e8d3ed291479 100644
--- a/src/USER-PTM/ptm_voronoi_cell.h
+++ b/src/USER-PTM/ptm_voronoi_cell.h
@@ -17,7 +17,7 @@
 
 #include "ptm_voronoi_config.h"
 
-namespace voro {
+namespace ptm_voro {
 
 /** \brief A class representing a single Voronoi cell.
  *
diff --git a/src/USER-PTM/ptm_voronoi_config.h b/src/USER-PTM/ptm_voronoi_config.h
index 86257e60cc74436556492371ee7d4cc65c20e931..46c5a4b9151965104fb987b3514832ac38407231 100644
--- a/src/USER-PTM/ptm_voronoi_config.h
+++ b/src/USER-PTM/ptm_voronoi_config.h
@@ -12,7 +12,7 @@
 #ifndef PTM_VOROPP_CONFIG_HH
 #define PTM_VOROPP_CONFIG_HH
 
-namespace voro {
+namespace ptm_voro {
 
 // These constants set the initial memory allocation for the Voronoi cell
 /** The initial memory allocation for the number of vertices. */