findsg.cpp 2.74 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
29
30
31
32
33
34
35
36
37
38
39
40
41
#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;
constexpr int g_prec = 6;



/**
 * find matching spacegroup
 */
std::vector<std::tuple<int, std::string, std::vector<t_mat>>> find_sgs(
	const std::vector<t_vec>& vecInit, const std::vector<t_vec>& vecFinal)
{
	return find_matching_sgs<t_vec, t_mat, t_real>(vecInit, vecFinal);
}



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

44
45
	std::vector<t_vec> vecFinal;
	/*{{ // test data
Tobias WEBER's avatar
Tobias WEBER committed
46
47
48
49
		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}),
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
	}}*/;

	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
69
70


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
		// 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
86
87
88
89
90
	std::size_t ctr = 1;
	for(const auto& pos : vecFinal)
		std::cout << "\t(" << ctr++ << ") " << pos << "\n";
	std::cout << std::endl;

91
92
93
94

	std::vector<t_vec> vecInit = vecFinal;


Tobias WEBER's avatar
Tobias WEBER committed
95
96
97
98
99
100
101
102
103
104
105
	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;

		auto matchingSGs = find_sgs(vecInit, vecFinal);

106
107
108
109
110
111
112
113
114
115
116
		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
117
118
119
120
121
122
123
124
125
126
		std::cout << "--------------------------------------------------------------------------------\n";
		std::cout << std::endl;

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

	return 0;
}