| Bsoft 2.0.5 Bernard's software package

mg_xtal.cpp
Go to the documentation of this file.
1
9 #include "mg_processing.h"
10 #include "mg_xtal.h"
11 #include "matrix_linear.h"
12 #include "Matrix.h"
13 #include "linked_list.h"
14 #include "Complex.h"
15 #include "utilities.h"
16 #include "timer.h"
17
18 // Declaration of global variables
19 extern int verbose; // Level of output to the screen
20
32 int mg_unitcell_vectors(Bmicrograph* mg)
33 {
34 long i;
35 vector<double> bx(2,0), by(2,0);
36 Matrix a(2,2);
37 Bstrucfac* sf;
38
39 for ( i = 0, sf = mg->sf; sf; sf = sf->next, i++ ) {
40 a[0][0] += sf->index[0]*sf->index[0];
41 a[0][1] += sf->index[0]*sf->index[1];
42 a[1][1] += sf->index[1]*sf->index[1];
43 bx[0] += sf->index[0]*sf->loc[0];
44 bx[1] += sf->index[1]*sf->loc[0];
45 by[0] += sf->index[0]*sf->loc[1];
46 by[1] += sf->index[1]*sf->loc[1];
47 }
48 a[1][0] = a[0][1];
49
50 if ( i < 2 ) {
51 cerr << "Error: Too few structure factors to calculate unit cell vectors!" << endl;
52 return -1;
53 }
54
55 a.LU_decomposition();
56 a.multiply_in_place(bx);
57 a.multiply_in_place(by);
58
59 mg->hvec[0] = bx[0];
60 mg->hvec[1] = by[0];
61 mg->kvec[0] = bx[1];
62 mg->kvec[1] = by[1];
63
64 return 0;
65 }
66
80 long mg_generate_reflections(Bmicrograph* mg, Vector3<double> real_size, double resolution)
81 {
82 if ( resolution < 2*mg->pixel_size ) resolution = 2*mg->pixel_size;
83
84 double hkl_lim = real_size[0]/resolution;
85 if ( real_size[1] > real_size[0] ) hkl_lim = real_size[1]/resolution;
86 double hkl_lim2 = hkl_lim*hkl_lim + 0.001;
87
88 if ( verbose )
89 cout << "Generating reflections to " << resolution << " Å" << endl;
90
91 long n(0), h, k, l, hmin, kmin, lmin, hmax, kmax, lmax;
92 double h2, k2, l2, hlen, klen;
93 Vector3<double> loc;
94 Bstrucfac* sf = NULL;
95
96 hlen = mg->hvec.length();
97 hmax = (long) (hkl_lim/hlen);
98 hmin = -hmax;
99
100 klen = mg->kvec.length();
101 kmax = (long) (hkl_lim/klen);
102 kmin = -kmax;
103
104 lmin = lmax = 0;
105
106 kill_list((char *) mg->sf, sizeof(Bstrucfac));
107 mg->sf = NULL;
108
109 if ( verbose ) {
110 cout << "real_size=" << real_size << endl;
111 cout << "hvec=" << mg->hvec << endl;
112 cout << "kvec=" << mg->kvec << endl;
113 cout << "hmax=" << hmax << " kmax=" << kmax << endl;
114 cout << "mg->origin=" << mg->origin << endl;
115 }
116
117 for ( l=lmin; l<=lmax; l++ ) {
118 l2 = l*l;
119 for ( k=kmin; k<=kmax; k++ ) {
120 k2 = k*klen;
121 k2 *= k2;
122 for ( h=hmin; h<=hmax; h++ ) {
123 h2 = h*hlen;
124 h2 *= h2;
125 if ( h2 + k2 + l2 <= hkl_lim2 ) {
126 loc[0] = h*mg->hvec[0] + k*mg->kvec[0] + l*mg->lvec[0];
127 loc[1] = h*mg->hvec[1] + k*mg->kvec[1] + l*mg->lvec[1];
128 loc[2] = h*mg->hvec[2] + k*mg->kvec[2] + l*mg->lvec[2];
129 sf = (Bstrucfac *) add_item((char **) &sf, sizeof(Bstrucfac));
130 if ( !mg->sf ) mg->sf = sf;
131 sf->index[0] = h;
132 sf->index[1] = k;
133 sf->index[2] = l;
134 sf->loc = loc;
135 sf->fom = sf->sel = 1;
136 n++;
137 }
138 }
139 }
140 }
141
142 return n;
143 }
144
152 int img_mask_reflections(Bimage* p, Bstrucfac* sflist, double radius)
153 {
154 long i, datasize = (long) p->size().volume();
155 // Vector3<long> mid(p->size()/2);
156 Vector3<double> loc;
157 Bstrucfac* sf = NULL;
158
159 Bimage* pmask = new Bimage(Float, p->compound_type(), p->size(), 1);
160 Complex<double> cv;
161
162 if ( p->compound_type() == TSimple ) { // Power spectrum
163 for ( sf = sflist; sf; sf = sf->next )
164 pmask->sphere(sf->loc, radius, 0, FILL_USER, 1);
165 for ( i=0; i<datasize; i++ )
166 if ( (*pmask)[i] < 1 ) p->set(i, 0);
167 } else if ( p->compound_type() == TComplex ) { // Standard Fourier transform
168 for ( sf = sflist; sf; sf = sf->next ) {
169 loc = vector3_set_PBC(sf->loc, p->size());
170 pmask->sphere(loc, radius, 0, FILL_USER, 1);
171 }
172 for ( i=0; i<datasize; i++ )
173 if ( (*pmask)[i] < 1 ) p->set(i, cv);;
174 }
175
176 delete pmask;
177
178 return 0;
179 }
180
181
mg_unitcell_vectors
int mg_unitcell_vectors(Bmicrograph *mg)
Calculates the unit cell vectors for a 2D crystal.
Definition: mg_xtal.cpp:32
Vector3::length
double length()
Definition: Vector3.h:222
vector3_set_PBC
Vector3< T1 > vector3_set_PBC(Vector3< T1 > coord, Vector3< T2 > box)
Definition: Vector3.h:682
img_mask_reflections
int img_mask_reflections(Bimage *p, Bstrucfac *sflist, double radius)
Masks the image using the list of reflections.
Definition: mg_xtal.cpp:152
utilities.h
Header file for general utilities.
Bstrucfac::loc
Vector3< double > loc
Definition: mg_processing.h:157
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:351
Bmicrograph::lvec
Vector3< double > lvec
Definition: mg_processing.h:225
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
Complex.h
Class for complex numbers.
add_item
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Definition: linked_list.cpp:26
Bmicrograph::pixel_size
double pixel_size
Definition: mg_processing.h:214
Bmicrograph::kvec
Vector3< double > kvec
Definition: mg_processing.h:224
mg_generate_reflections
long mg_generate_reflections(Bmicrograph *mg, Vector3< double > real_size, double resolution)
Generates reflections given the unit cell vectors.
Definition: mg_xtal.cpp:80
Matrix::multiply_in_place
int multiply_in_place(vector< double > &vec)
Definition: matrix.cpp:49
Matrix.h
Generalized matrix class.
verbose
int verbose
TComplex
Definition: Bimage.h:59
Bmicrograph::sf
Bstrucfac * sf
Definition: mg_processing.h:243
TSimple
Definition: Bimage.h:58
timer.h
Utilities for timing functions.
Float
Definition: utilities.h:157
Bimage
General image parameter class.
Definition: Bimage.h:163
Matrix::LU_decomposition
double LU_decomposition()
Matrix inversion by LU decomposition.
Definition: matrix.cpp:78
linked_list.h
Header file for generalized linked list functions.
Bstrucfac
Definition: mg_processing.h:155
mg_xtal.h
Header file for functions to process crystallographic data.
Bimage::sphere
int sphere(Vector3< double > center, double radius, double width=0, int fill_type=0, double fill=0)
Fills a sphere within an image with a uniform value.
Definition: Bimage_edit.cpp:438
Bmicrograph
Definition: mg_processing.h:200
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:220
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
Bmicrograph::hvec
Vector3< double > hvec
Definition: mg_processing.h:223
Bstrucfac::index
Vector3< int > index
Definition: mg_processing.h:158
Bstrucfac::next
Bstrucfac * next
Definition: mg_processing.h:156
FILL_USER
#define FILL_USER
Definition: utilities.h:172
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1096
Complex
Definition: Complex.h:23
Matrix
Definition: Matrix.h:21
kmin
long kmin(long i, long hk)
Definition: Bimage_filter.cpp:17
matrix_linear.h
Header file for matrix functions.
kmax
long kmax(long i, long km, long m)
Definition: Bimage_filter.cpp:22
Vector3< double >
mg_processing.h
Header file for micrograph processing.
Vector3::volume
double volume()
Definition: Vector3.h:235
Bstrucfac::fom
double fom
Definition: mg_processing.h:163
Bstrucfac::sel
long sel
Definition: mg_processing.h:164