CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
#include <typedef.h>
2
3
#include <getput.h>
4
#include <matrix.h>
5
#include <orbit.h>
6
#include <bravais.h>
7
#include <base.h>
8
#include <tools.h>
9
#include <zass.h>
10
#include <datei.h>
11
#include <presentation.h>
12
13
int INFO_LEVEL;
14
extern int SFLAG;
15
16
matrix_TYP *translation_lattice(matrix_TYP **G,int number,matrix_TYP *P);
17
18
int main(int argc,char **argv){
19
20
bravais_TYP *G,
21
*H;
22
23
matrix_TYP *X,
24
**XX,
25
**base,
26
*T,
27
**COZ;
28
29
bahn **strong;
30
31
int i,
32
j,
33
k,
34
type, /* TRUE iff the function has been called via
35
...Standart_affine_form */
36
kgv,
37
cozanz;
38
39
char comment[1000],
40
file[1000];
41
42
G = NULL;
43
H = NULL;
44
X = NULL;
45
T = NULL;
46
47
read_header(argc,argv);
48
49
#define OTHER_NAME "Standard_affine_form"
50
if (strlen(argv[0]) < strlen(OTHER_NAME)){
51
/* it can't have been called via .....OTHER_NAME */
52
type = FALSE;
53
}
54
else{
55
type = (strcmp(argv[0]+(strlen(argv[0])-strlen(OTHER_NAME)),
56
OTHER_NAME) == 0);
57
}
58
59
60
if ((type && FILEANZ < 1) ||
61
(!type && ((is_option('h') && optionnumber('h')==0)||
62
(FILEANZ < 1) ||
63
((FILEANZ < 2) && (is_option('r')))))){
64
if (type){
65
printf("Usage: %s 'file1' 'file2' [-t]\n",argv[0]);
66
printf("\n");
67
printf("file1: bravais_TYP containing a space group G.\n");
68
printf("file2: matrix_TYP contatining a presentation of the point\n");
69
printf(" group of G.\n");
70
printf("\n");
71
printf("Transforms the space group with generators in file1 into standard\n");
72
printf("form, ie. the translation lattice is transformed to Z^n.\n");
73
printf("In case the translation subgroup has dimension smaller than n, i.\n");
74
printf("e. the group is not an n-dimensional space group, the program\n");
75
printf("will indicate an error, gives the rank, and exit.\n");
76
printf("\n");
77
printf("Options:\n");
78
printf("-t : The transforming matrix will be given as well.\n");
79
printf("\n");
80
printf("Cf. Extensions, Vector_systems\n");
81
printf("Note: This program is a synonym for Extract -t.\n");
82
}
83
else{
84
printf("Usage: %s 'file1' ['file2'] [-c] [-p] [-f] [-r [-D]] [-t=n]\n",argv[0]);
85
printf("\n");
86
printf("file1: bravais_TYP containing a space or (in case of option -r) a point group.\n");
87
printf("file2: matrix_TYP only used with options -r and -t, cf. below. \n");
88
printf("\n");
89
printf("Extracts the linear part of the affine (space) group in file1.\n");
90
printf("Note this is the point group of the space group in case the space \n");
91
printf("group is given in standard form.\n");
92
printf("\n");
93
printf("Options:\n");
94
printf("-p : extracts the linear part (default).\n");
95
printf("-c : extracts the translational part as a vector system (1-cozycle).\n");
96
printf("-f : do not calculate the formspace of the point group.\n");
97
printf("-r : reverses the process: Reads in the generators of the point group \n");
98
printf(" of file1 and multiple vector systems for these generators from file2 \n");
99
printf(" and outputs the resulting space groups. Overwrites any other option.\n");
100
printf("-D : this option only works together with '-r'. The spacegroups are written\n");
101
printf(" to 'file.i' with i = 1, ...\n");
102
printf("-t=n : transform the space group with generators in file1 into standard\n");
103
printf(" form, ie. the translation lattice is transformed to Z^n. If a \n");
104
printf(" parameter n>0 is specified, the transforming matrix will be\n");
105
printf(" given as well. NOTE: For the -t-option file2 must contain a \n");
106
printf(" presentation for the point group. If the translation lattice \n");
107
printf(" is of smaller rank, it will give the rank. Synonymous command:\n");
108
printf(" Standard_affine_form\n");
109
printf("-T : RESERVED\n");
110
printf("\n");
111
printf("Cf. Extensions, Vector_systems\n");
112
}
113
114
115
if (is_option('h')){
116
exit(0);
117
}
118
else{
119
exit(31);
120
}
121
}
122
123
INFO_LEVEL = optionnumber('h');
124
125
if (INFO_LEVEL & 12){
126
SFLAG = 1;
127
}
128
129
G = get_bravais(FILENAMES[0]);
130
131
if (is_option('t') || type){
132
133
if (FILEANZ == 2){
134
XX = mget_mat(FILENAMES[1],&i);
135
if (i>1){
136
fprintf(stderr,"you should only give a single matrix as presention\n");
137
exit(3);
138
}
139
X = XX[0];
140
free(XX);
141
142
}
143
else{
144
145
/* get the point group */
146
H = init_bravais(G->dim-1);
147
H->gen_no = G->gen_no;
148
H->gen = (matrix_TYP **) malloc(H->gen_no * sizeof(matrix_TYP *));
149
for (i=0;i<H->gen_no;i++){
150
H->gen[i] = copy_mat(G->gen[i]);
151
real_mat(H->gen[i],G->dim,G->dim-1);
152
real_mat(H->gen[i],G->dim-1,G->dim-1);
153
}
154
155
156
/* calculate a presentation */
157
base = get_base(H);
158
159
strong = strong_generators(base,H,TRUE);
160
161
X = pres(strong,H,NULL);
162
163
for (i=0;i<H->dim;i++){
164
free_mat(base[i]);
165
free_bahn(strong[i]);
166
free(strong[i]);
167
}
168
free(strong);
169
free(base);
170
free_bravais(H); H = NULL;
171
}
172
173
if (is_option('T')){
174
real_mat(X,X->rows+G->dim-1,X->cols);
175
for (i=0;i<G->dim-1;i++){
176
X->array.SZ[X->rows-G->dim+1+i][0] = G->gen_no - i ;
177
}
178
}
179
180
/* set the transformation matrix */
181
T = translation_lattice(G->gen,G->gen_no,X);
182
free_mat(X);
183
X = NULL;
184
185
/* echo the rank if needed */
186
if (T->rows != T->cols){
187
fprintf(stderr,"The rank of the translation lattice is %d\n",T->cols);
188
exit(3);
189
}
190
191
real_mat(T,T->rows+1,T->cols+1);
192
193
/* paranoia */
194
rat2kgv(T);
195
196
T->array.SZ[T->rows-1][T->cols-1] = T->kgv;
197
Check_mat(T);
198
199
if ((optionnumber('t')>0 && !type) ||
200
(is_option('t') && type)){
201
sprintf(comment,"transformation matrix for space group in %s",
202
FILENAMES[0]);
203
put_mat(T,NULL,comment,2);
204
}
205
206
/* we should also calculate a positive definite, point group
207
invariant form, and transform the group according to a mink_red
208
of this form. left for further development */
209
210
/* now transform the group */
211
H = init_bravais(G->dim);
212
H->gen = (matrix_TYP **) malloc(G->gen_no * sizeof(matrix_TYP *));
213
H->gen_no = G->gen_no;
214
X = mat_inv(T);
215
for (i=0;i<H->gen_no;i++){
216
H->gen[i] = mat_kon(X,G->gen[i],T);
217
}
218
219
sprintf(comment,"space group of %s on Z^n",
220
FILENAMES[0]);
221
put_bravais(H,NULL,NULL);
222
}
223
else{
224
if (is_option('r')){
225
COZ = mget_mat(FILENAMES[1], &cozanz);
226
for (k = 0; k < cozanz; k++){
227
rat2kgv(COZ[k]);
228
Check_mat(COZ[k]);
229
convert_cocycle_to_column(&COZ[k],1,G->dim,G->gen_no);
230
231
/* is it a valid cozycle? */
232
if ((G->dim * G->gen_no != COZ[k]->rows) || (COZ[k]->cols != 1)){
233
fprintf(stderr,"The cozycle is not compatible to this point group\n");
234
fprintf(stderr,"It should have %d * %d = %d rows\n",G->dim,G->gen_no,
235
G->dim*G->gen_no);
236
exit(3);
237
}
238
H = init_bravais(G->dim+1);
239
H->gen_no = G->gen_no;
240
H->gen = (matrix_TYP **) malloc(G->gen_no * sizeof(matrix_TYP *));
241
242
for (i=0;i<H->gen_no;i++){
243
H->gen[i] = copy_mat(G->gen[i]);
244
rat2kgv(H->gen[i]);
245
Check_mat(H->gen[i]);
246
real_mat(H->gen[i],H->dim,H->dim);
247
iscal_mul(H->gen[i],COZ[k]->kgv);
248
H->gen[i]->kgv = H->gen[i]->kgv * COZ[k]->kgv;
249
for (j=0;j<H->dim-1;j++)
250
H->gen[i]->array.SZ[j][H->dim-1] = COZ[k]->array.SZ[i*(H->dim-1)+j][0];
251
H->gen[i]->array.SZ[H->dim-1][H->dim-1] = COZ[k]->kgv;
252
Check_mat(H->gen[i]);
253
}
254
if (is_option('D')){
255
sprintf(file, "%s.%d", FILENAMES[0], k + 1);
256
sprintf(comment, "space group to the point group of %s and the %d-th cozycle of %s",
257
FILENAMES[0], k+1, FILENAMES[1]);
258
put_bravais(H, file, comment);
259
}
260
else{
261
sprintf(comment, "space group to the point group of %s and the %d-th cozycle of %s",
262
FILENAMES[0], k+1, FILENAMES[1]);
263
put_bravais(H, NULL, comment);
264
}
265
free_bravais(H);
266
free_mat(COZ[k]);
267
}
268
H = NULL;
269
free(COZ);
270
}
271
else if (is_option('p') || (!is_option('p') && ! is_option('c'))){
272
/* extract the point group */
273
H = init_bravais(G->dim-1);
274
275
H->gen_no = G->gen_no;
276
H->gen = (matrix_TYP **) malloc(G->gen_no * sizeof(matrix_TYP *));
277
for (i=0;i<H->gen_no;i++){
278
H->gen[i] = copy_mat(G->gen[i]);
279
real_mat(H->gen[i],H->dim,G->dim);
280
real_mat(H->gen[i],H->dim,H->dim);
281
rat2kgv(H->gen[i]);
282
Check_mat(H->gen[i]);
283
}
284
285
if (!is_option('f'))
286
H->form = formspace(H->gen,H->gen_no,1,&H->form_no);
287
288
/* output */
289
sprintf(comment,"point group to the space group of %s",FILENAMES[0]);
290
put_bravais(H,NULL,comment);
291
free_bravais(H);
292
H = NULL;
293
}
294
if (is_option('c')){
295
X = init_mat(G->gen_no * (G->dim-1),1,"");
296
kgv = 1;
297
for (i=0;i<G->gen_no;i++){
298
rat2kgv(G->gen[i]);
299
kgv = kgv*G->gen[i]->kgv/GGT(kgv,G->gen[i]->kgv);
300
}
301
302
303
/* set the cozycle */
304
X->kgv = kgv;
305
for(i=0;i<G->gen_no;i++)
306
for (j=0;j<G->dim-1;j++)
307
X->array.SZ[i*(G->dim-1)+j][0] = X->kgv/G->gen[i]->kgv *
308
G->gen[i]->array.SZ[j][G->dim-1];
309
310
Check_mat(X);
311
sprintf(comment,"cozycle to the group of %s",FILENAMES[0]);
312
put_cocycle(X,G->dim-1,G->gen_no,NULL,comment);
313
}
314
}
315
316
/* cleaning up */
317
if (G!=NULL) free_bravais(G);
318
if (H!=NULL) free_bravais(H);
319
if (X!=NULL) free_mat(X);
320
if (T!=NULL) free_mat(T);
321
322
exit(0);
323
324
} /* main */
325
326