findsg.cpp 2.5 KB
Newer Older
Tobias WEBER's avatar
Tobias WEBER committed
1
2
3
4
5
6
7
8
9
10
11
/**
 * finds a matching space group
 * @author Tobias Weber <tweber@ill.fr>
 * @date jan-2020
 * @license GPLv3, see 'LICENSE' file
 */

#include "../structfact/loadcif.h"
#include "libs/_cxx20/math_algos.h"

#include <gemmi/version.hpp>
12
#include <boost/algorithm/string.hpp>
Tobias WEBER's avatar
Tobias WEBER committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <memory>


using t_real = double;
using t_vec = std::vector<t_real>;
using t_mat = m::mat<t_real, std::vector>;

constexpr t_real g_eps = 1e-6;


/**
 * entry point
 */
int main(int argc, char** argv)
{
29
	std::cout << "Input atomic positions, 'e' or ENTER to end." << std::endl;
Tobias WEBER's avatar
Tobias WEBER committed
30

31
32
	std::vector<t_vec> vecFinal;
	/*{{ // test data
Tobias WEBER's avatar
Tobias WEBER committed
33
34
35
36
		m::create<t_vec>({ 0.1,  0.1,  0.1}),
		m::create<t_vec>({ 0.4, -0.1, -0.4}),
		m::create<t_vec>({-0.1, -0.4,  0.4}),
		m::create<t_vec>({-0.4,  0.4, -0.1}),
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
	}}*/;

	std::size_t atomnr = 1;
	while(1)
	{
		std::string strpos;
		std::cout << "Position " << atomnr++ << ": ";

		std::getline(std::cin, strpos);
		boost::trim(strpos);
		if(strpos == "" || strpos == "e")
			break;

		// tokenise
		std::vector<std::string> vecstr;
		boost::split(vecstr, strpos, [](char c) -> bool
		{
			return c == ' ' || c== '\t' || c == ',' || c == ';';
		}, boost::token_compress_on);
Tobias WEBER's avatar
Tobias WEBER committed
56
57


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
		// convert to real vector
		t_vec vecPos;
		for(const std::string& str : vecstr)
			vecPos.emplace_back(std::stod(str));

		// fill up possibly missing coordinates
		while(vecPos.size() < 3)
			vecPos.push_back(0);
		vecPos.resize(3);

		vecFinal.emplace_back(std::move(vecPos));
	}


	std::cout << "\nFull set of positions to match:\n";
Tobias WEBER's avatar
Tobias WEBER committed
73
74
75
76
77
	std::size_t ctr = 1;
	for(const auto& pos : vecFinal)
		std::cout << "\t(" << ctr++ << ") " << pos << "\n";
	std::cout << std::endl;

78
79
80
81

	std::vector<t_vec> vecInit = vecFinal;


Tobias WEBER's avatar
Tobias WEBER committed
82
83
84
85
86
87
88
89
90
	while(1)
	{
		std::cout << "\n--------------------------------------------------------------------------------\n";
		std::cout << "Base set of positions:\n";
		ctr = 1;
		for(const auto& pos : vecInit)
			std::cout << "\t(" << ctr++ << ") " << pos << "\n";
		std::cout << std::endl;

Tobias WEBER's avatar
Tobias WEBER committed
91
		auto matchingSGs = find_matching_sgs<t_vec, t_mat, t_real>(vecInit, vecFinal, g_eps);
Tobias WEBER's avatar
Tobias WEBER committed
92

93
94
95
96
97
98
99
100
101
102
103
		if(matchingSGs.size())
		{
			std::cout << "Matching space groups:\n";
			ctr = 1;
			for(const auto& sg : matchingSGs)
				std::cout << "\t(" << ctr++ << ") " << std::get<1>(sg) << "\n";
		}
		else
		{
			std::cout << "No matching space groups.\n";
		}
Tobias WEBER's avatar
Tobias WEBER committed
104
105
106
107
108
109
110
111
112
113
		std::cout << "--------------------------------------------------------------------------------\n";
		std::cout << std::endl;

		vecInit.pop_back();
		if(vecInit.size() == 0)
			break;
	}

	return 0;
}