-
Notifications
You must be signed in to change notification settings - Fork 3
/
framework.py
4584 lines (3639 loc) · 178 KB
/
framework.py
1
2
3
4
5
6
7
8
9
10
11
12
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# Created by Felipe Lopes de Oliveira
# Distributed under the terms of the MIT License.
"""
The Framework class implements definitions and methods for a Framework buiding
"""
import os
import copy
import numpy as np
# Import pymatgen
from pymatgen.core import Lattice, Structure
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.transformations.advanced_transformations import CubicSupercellTransformation
from scipy.spatial.transform import Rotation as R
# Import pycofbuilder exceptions
from pycofbuilder.exceptions import (BondLenghError,
BBConnectivityError)
# Import pycofbuilder building_block
from pycofbuilder.building_block import BuildingBlock
# Import pycofbuilder topology data
from pycofbuilder.data.topology import TOPOLOGY_DICT
# Import pycofbuilder tools
from pycofbuilder.tools import (get_bond_atom,
cell_to_cellpar,
cellpar_to_cell,
rotation_matrix_from_vectors,
unit_vector,
angle,
get_framework_symm_text,
get_bonds)
# Import pycofbuilder io_tools
from pycofbuilder.io_tools import (save_chemjson,
save_cif,
save_xyz,
save_turbomole,
save_vasp,
save_xsf,
save_pdb,
save_pqr,
save_qe,
save_gjf)
from pycofbuilder.logger import create_logger
class Framework():
"""
A class used to represent a Covalent Organic Framework as a reticular entity.
...
Attributes
----------
name : str
Name of the material
out_dir : str
Path to save the results.
If not defined, a `out` folder will be created in the current directory.
verbosity : str
Control the printing options. Can be 'none', 'normal', or 'debug'.
Default: 'normal'
save_bb : bool
Control the saving of the building blocks.
Default: True
lib_path : str
Path for saving the building block files.
If not defined, a `building_blocks` folder will be created in the current directory.
topology : str = None
dimention : str = None
lattice : str = None
lattice_sgs : str = None
space_group : str = None
space_group_n : str = None
stacking : str = None
mass : str = None
composition : str = None
charge : int = 0
multiplicity : int = 1
chirality : bool = False
atom_types : list = []
atom_pos : list = []
lattice : list = [[], [], []]
symm_tol : float = 0.2
angle_tol : float = 0.2
dist_threshold : float = 0.8
available_2D_topologies : list
List of available 2D topologies
available_3D_topologies : list
List of available 3D topologies
available_topologies : list
List of all available topologies
available_stacking : list
List of available stakings for all 2D topologies
lib_bb : str
String with the name of the folder containing the building block files
Default: bb_lib
"""
def __init__(self, name: str = None, **kwargs):
self.name: str = name
self.out_path: str = kwargs.get('out_dir', os.path.join(os.getcwd(), 'out'))
self.save_bb: bool = kwargs.get('save_bb', True)
self.bb_out_path: str = kwargs.get('bb_out_path', os.path.join(self.out_path, 'building_blocks'))
self.logger = create_logger(level=kwargs.get('log_level', 'info'),
format=kwargs.get('log_format', 'simple'),
save_to_file=kwargs.get('save_to_file', False),
log_filename=kwargs.get('log_filename', 'pycofbuilder.log'))
self.symm_tol = kwargs.get('symm_tol', 0.1)
self.angle_tol = kwargs.get('angle_tol', 0.5)
self.dist_threshold = kwargs.get('dist_threshold', 0.8)
self.bond_threshold = kwargs.get('bond_threshold', 1.3)
self.bb1_name = None
self.bb2_name = None
self.topology = None
self.stacking = None
self.smiles = None
self.atom_types = []
self.atom_pos = []
self.atom_labels = []
self.cellMatrix = np.eye(3)
self.cellParameters = np.array([1, 1, 1, 90, 90, 90]).astype(float)
self.bonds = []
self.lattice_sgs = None
self.space_group = None
self.space_group_n = None
self.dimention = None
self.n_atoms = self.get_n_atoms()
self.mass = None
self.composition = None
self.charge = 0
self.multiplicity = 1
self.chirality = False
self.available_2D_top = ['HCB', 'HCB_A',
'SQL', 'SQL_A',
'KGD',
'HXL', 'HXL_A',
'FXT', 'FXT_A']
# To add: ['dia', 'bor', 'srs', 'pts', 'ctn', 'rra', 'fcc', 'lon', 'stp', 'acs', 'tbo', 'bcu', 'fjh', 'ceq']
self.available_3D_top = ['DIA', 'DIA_A', 'BOR'] # Temporary
self.available_topologies = self.available_2D_top + self.available_3D_top
# Define available stackings for all 2D topologies
self.available_stacking = {
'HCB': ['A', 'AA', 'AB1', 'AB2', 'AAl', 'AAt', 'ABC1', 'ABC2'],
'HCB_A': ['A', 'AA', 'AB1', 'AB2', 'AAl', 'AAt', 'ABC1', 'ABC2'],
'SQL': ['A', 'AA', 'AB1', 'AB2', 'AAl', 'AAt', 'ABC1', 'ABC2'],
'SQL_A': ['A', 'AA', 'AB1', 'AB2', 'AAl', 'AAt', 'ABC1', 'ABC2'],
'KGD': ['A', 'AA', 'AB1', 'AB2', 'AAl', 'AAt', 'ABC1', 'ABC2'],
'HXL_A': ['A', 'AA', 'AB1', 'AB2', 'AAl', 'AAt', 'ABC1', 'ABC2'],
'FXT': ['A', 'AA', 'AB1', 'AB2', 'AAl', 'AAt', 'ABC1', 'ABC2'],
'FXT_A': ['A', 'AA', 'AB1', 'AB2', 'AAl', 'AAt', 'ABC1', 'ABC2'],
'DIA': [str(i + 1) for i in range(15)],
'DIA_A': [str(i + 1) for i in range(15)],
'BOR': [str(i + 1) for i in range(15)]
}
if self.name is not None:
self.from_name(self.name)
def __str__(self) -> str:
return self.as_string()
def __repr__(self) -> str:
return f'Framework({self.bb1_name}, {self.bb2_name}, {self.topology}, {self.stacking})'
def as_string(self) -> str:
"""
Returns a string with the Framework information.
"""
fram_str = f'Name: {self.name}\n'
# Get the formula of the framework
if self.composition is not None:
fram_str += f'Full Formula ({self.composition})\n'
fram_str += f'Reduced Formula: ({self.composition})\n'
else:
fram_str += 'Full Formula ()\n'
fram_str += 'Reduced Formula: \n'
fram_str += 'abc : {:11.6f} {:11.6f} {:11.6f}\n'.format(*self.cellParameters[:3])
fram_str += 'angles: {:11.6f} {:11.6f} {:11.6f}\n'.format(*self.cellParameters[3:])
fram_str += 'A: {:11.6f} {:11.6f} {:11.6f}\n'.format(*self.cellMatrix[0])
fram_str += 'B: {:11.6f} {:11.6f} {:11.6f}\n'.format(*self.cellMatrix[1])
fram_str += 'C: {:11.6f} {:11.6f} {:11.6f}\n'.format(*self.cellMatrix[2])
fram_str += f'Cartesian Sites ({self.n_atoms})\n'
fram_str += ' # Type a b c label\n'
fram_str += '--- ---- -------- -------- -------- -------\n'
for i in range(len(self.atom_types)):
fram_str += '{:3d} {:4s} {:8.5f} {:8.5f} {:8.5f} {:>7}\n'.format(i,
self.atom_types[i],
self.atom_pos[i][0],
self.atom_pos[i][1],
self.atom_pos[i][2],
self.atom_labels[i])
return fram_str
def get_n_atoms(self) -> int:
"""
Returns the number of atoms in the unitary cell
"""
return len(self.atom_types)
def get_available_topologies(self, dimensionality: str = 'all', print_result: bool = True):
"""
Get the available topologies implemented in the class.
Parameters
----------
dimensionality : str, optional
The dimensionality of the topologies to be printed. Can be 'all', '2D' or '3D'.
Default: 'all'
print_result: bool, optional
If True, the available topologies are printed.
Returns
-------
dimensionality_list: list
A list with the available topologies.
"""
dimensionality_error = f'Dimensionality must be one of the following: all, 2D, 3D, not {dimensionality}'
assert dimensionality in ['all', '2D', '3D'], dimensionality_error
dimensionality_list = []
if dimensionality == 'all' or dimensionality == '2D':
if print_result:
print('Available 2D Topologies:')
for i in self.available_2D_top:
if print_result:
print(i.upper())
dimensionality_list.append(i)
if dimensionality == 'all' or dimensionality == '3D':
if print_result:
print('Available 3D Topologies:')
for i in self.available_3D_top:
if print_result:
print(i.upper())
dimensionality_list.append(i)
return dimensionality_list
def check_name_concistency(self, FrameworkName) -> tuple[str, str, str, str]:
"""
Checks if the name is in the correct format and returns a
tuple with the building blocks names, the net and the stacking.
In case the name is not in the correct format, an error is raised.
Parameters
----------
FrameworkName : str, required
The name of the COF to be created
Returns
-------
tuple[str, str, str, str]
A tuple with the building blocks names, the net and the stacking.
"""
string_error = 'FrameworkName must be a string'
assert isinstance(FrameworkName, str), string_error
name_error = 'FrameworkName must be in the format: BB1-BB2-Net-Stacking'
assert len(FrameworkName.split('-')) == 4, name_error
bb1_name, bb2_name, Net, Stacking = FrameworkName.split('-')
net_error = f'{Net} not in the available list: {self.available_topologies}'
assert Net in self.available_topologies, net_error
stacking_error = f'{Stacking} not in the available list: {self.available_stacking[Net]}'
assert Stacking in self.available_stacking[Net], stacking_error
return bb1_name, bb2_name, Net, Stacking
def from_name(self, FrameworkName, **kwargs) -> None:
"""Creates a COF from a given FrameworkName.
Parameters
----------
FrameworkName : str, required
The name of the COF to be created
Returns
-------
COF : Framework
The COF object
"""
bb1_name, bb2_name, Net, Stacking = self.check_name_concistency(FrameworkName)
bb1 = BuildingBlock(name=bb1_name, bb_out_path=self.bb_out_path, save_bb=self.save_bb)
bb2 = BuildingBlock(name=bb2_name, bb_out_path=self.bb_out_path, save_bb=self.save_bb)
self.from_building_blocks(bb1, bb2, Net, Stacking, **kwargs)
def from_building_blocks(self,
bb1: BuildingBlock,
bb2: BuildingBlock,
net: str,
stacking: str,
**kwargs):
"""Creates a COF from the building blocks.
Parameters
----------
BB1 : BuildingBlock, required
The first building block
BB2 : BuildingBlock, required
The second building block
Net : str, required
The network of the COF
Stacking : str, required
The stacking of the COF
Returns
-------
COF : Framework
The COF object
"""
self.name = f'{bb1.name}-{bb2.name}-{net}-{stacking}'
self.bb1_name = bb1.name
self.bb2_name = bb2.name
self.topology = net
self.stacking = stacking
# Check if the BB1 has the smiles attribute
if hasattr(bb1, 'smiles') and hasattr(bb2, 'smiles'):
self.smiles = f'{bb1.smiles}.{bb2.smiles}'
else:
print('WARNING: The smiles attribute is not available for the building blocks')
net_build_dict = {
'HCB': self.create_hcb_structure,
'HCB_A': self.create_hcb_a_structure,
'SQL': self.create_sql_structure,
'SQL_A': self.create_sql_a_structure,
'KGD': self.create_kgd_structure,
# 'HXL': self.create_hxl_structure,
'HXL_A': self.create_hxl_a_structure,
'FXT': self.create_fxt_structure,
'FXT_A': self.create_fxt_a_structure,
'DIA': self.create_dia_structure,
'DIA_A': self.create_dia_a_structure,
'BOR': self.create_bor_structure
}
result = net_build_dict[net](bb1, bb2, stacking, **kwargs)
structure = Structure(
self.cellMatrix,
self.atom_types,
self.atom_pos,
coords_are_cartesian=True,
site_properties={'source': self.atom_labels}
)
self.bonds = get_bonds(structure, self.bond_threshold)
return result
def save(self,
fmt: str = 'cif',
supercell: list = (1, 1, 1),
save_dir=None,
primitive=False,
save_bonds=True) -> None:
"""
Save the structure in a specif file format.
Parameters
----------
fmt : str, optional
The file format to be saved
Can be `json`, `cif`, `xyz`, `turbomole`, `vasp`, `xsf`, `pdb`, `pqr`, `qe`.
Default: 'cif'
supercell : list, optional
The supercell to be used to save the structure.
Default: [1,1,1]
save_dir : str, optional
The path to save the structure. By default, the structure is saved in a
`out` folder created in the current directory.
primitive : bool, optional
If True, the primitive cell is saved. Otherwise, the conventional cell is saved.
Default: False
"""
save_dict = {
'cjson': save_chemjson,
'cif': save_cif,
'xyz': save_xyz,
'turbomole': save_turbomole,
'vasp': save_vasp,
'xsf': save_xsf,
'pdb': save_pdb,
'pqr': save_pqr,
'qe': save_qe,
'gjf': save_gjf
}
file_format_error = f'Format must be one of the following: {save_dict.keys()}'
assert fmt in save_dict.keys(), file_format_error
if primitive:
structure = self.prim_structure
else:
structure = Structure(
self.cellMatrix,
self.atom_types,
self.atom_pos,
coords_are_cartesian=True,
site_properties={'source': self.atom_labels}
)
structure.make_supercell(supercell)
if save_bonds:
bonds = get_bonds(structure, self.bond_threshold)
else:
bonds = []
structure_dict = structure.as_dict()
cell = structure_dict['lattice']['matrix']
atom_types = [site['species'][0]['element'] for site in structure_dict['sites']]
atom_labels = [site['properties']['source'] for site in structure_dict['sites']]
atom_pos = [site['xyz'] for site in structure_dict['sites']]
if save_dir is None:
save_path = self.out_path
else:
save_path = save_dir
save_dict[fmt](path=save_path,
file_name=self.name,
cell=cell,
atom_types=atom_types,
atom_labels=atom_labels,
atom_pos=atom_pos,
bonds=bonds)
def make_cubic(self,
min_length=10,
force_diagonal=False,
force_90_degrees=True,
min_atoms=None,
max_atoms=None,
angle_tolerance=1e-3):
"""
Transform the primitive structure into a supercell with alpha, beta, and
gamma equal to 90 degrees. The algorithm will iteratively increase the size
of the supercell until the largest inscribed cube's side length is at least 'min_length'
and the number of atoms in the supercell falls in the range ``min_atoms < n < max_atoms``.
Parameters
----------
min_length : float, optional
Minimum length of the cubic cell (default is 10)
force_diagonal : bool, optional
If True, generate a transformation with a diagonal transformation matrix (default is False)
force_90_degrees : bool, optional
If True, force the angles to be 90 degrees (default is True)
min_atoms : int, optional
Minimum number of atoms in the supercell (default is None)
max_atoms : int, optional
Maximum number of atoms in the supercell (default is None)
angle_tolerance : float, optional
The angle tolerance for the transformation (default is 1e-3)
"""
cubic_dict = CubicSupercellTransformation(
min_length=min_length,
force_90_degrees=force_90_degrees,
force_diagonal=force_diagonal,
min_atoms=min_atoms,
max_atoms=max_atoms,
angle_tolerance=angle_tolerance
).apply_transformation(self.prim_structure).as_dict()
self.cellMatrix = np.array(cubic_dict['lattice']['matrix']).astype(float)
self.cellParameters = cell_to_cellpar(self.cellMatrix)
self.atom_types = [i['label'] for i in cubic_dict['sites']]
self.atom_pos = [i['xyz'] for i in cubic_dict['sites']]
self.atom_labels = [i['properties']['source'] for i in cubic_dict['sites']]
# --------------- Net creation methods -------------------------- #
def create_hcb_structure(self,
BB_T3_A,
BB_T3_B,
stacking: str = 'AA',
slab: float = 10.0,
shift_vector: list = (1.0, 1.0, 0),
tilt_angle: float = 5.0):
"""Creates a COF with HCB network.
The HCB net is composed of two tripodal building blocks.
Parameters
----------
BB_T3_1 : BuildingBlock, required
The BuildingBlock object of the tripodal Buiding Block A
BB_T3_2 : BuildingBlock, required
The BuildingBlock object of the tripodal Buiding Block B
stacking : str, optional
The stacking pattern of the COF layers (default is 'AA')
slab : float, optional
Default parameter for the interlayer slab (default is 10.0)
shift_vector: list, optional
Shift vector for the AAl and AAt stakings (defatult is [1.0,1.0,0])
tilt_angle: float, optional
Tilt angle for the AAt staking in degrees (default is 5.0)
Returns
-------
list
A list of strings containing:
1. the structure name,
2. lattice type,
3. hall symbol of the cristaline structure,
4. space group,
5. number of the space group,
6. number of operation symmetry
"""
connectivity_error = 'Building block {} must present connectivity {} not {}'
if BB_T3_A.connectivity != 3:
self.logger.error(connectivity_error.format('A', 3, BB_T3_A.connectivity))
raise BBConnectivityError(3, BB_T3_A.connectivity)
if BB_T3_B.connectivity != 3:
self.logger.error(connectivity_error.format('B', 3, BB_T3_B.connectivity))
raise BBConnectivityError(3, BB_T3_B.connectivity)
self.name = f'{BB_T3_A.name}-{BB_T3_B.name}-HCB-{stacking}'
self.topology = 'HCB'
self.staking = stacking
self.dimension = 2
self.charge = BB_T3_A.charge + BB_T3_B.charge
self.chirality = BB_T3_A.chirality or BB_T3_B.chirality
self.logger.debug(f'Starting the creation of {self.name}')
# Detect the bond atom from the connection groups type
bond_atom = get_bond_atom(BB_T3_A.conector, BB_T3_B.conector)
self.logger.debug('{} detected as bond atom for groups {} and {}'.format(bond_atom,
BB_T3_A.conector,
BB_T3_B.conector))
# Replace "X" the building block
BB_T3_A.replace_X(bond_atom)
# Remove the "X" atoms from the the building block
BB_T3_A.remove_X()
BB_T3_B.remove_X()
# Get the topology information
topology_info = TOPOLOGY_DICT[self.topology]
# Measure the base size of the building blocks
size = BB_T3_A.size[0] + BB_T3_B.size[0]
# Calculate the delta size to add to the c parameter
delta_a = abs(max(np.transpose(BB_T3_A.atom_pos)[2])) + abs(min(np.transpose(BB_T3_A.atom_pos)[2]))
delta_b = abs(max(np.transpose(BB_T3_B.atom_pos)[2])) + abs(min(np.transpose(BB_T3_B.atom_pos)[2]))
delta_max = max([delta_a, delta_b])
# Calculate the cell parameters
a = topology_info['a'] * size
b = topology_info['b'] * size
c = topology_info['c'] + delta_max
alpha = topology_info['alpha']
beta = topology_info['beta']
gamma = topology_info['gamma']
if self.stacking == 'A':
c = slab
# Create the lattice
self.cellMatrix = Lattice.from_parameters(a, b, c, alpha, beta, gamma)
self.cellParameters = np.array([a, b, c, alpha, beta, gamma]).astype(float)
# Create the structure
self.atom_types = []
self.atom_labels = []
self.atom_pos = []
# Add the A1 building blocks to the structure
vertice_data = topology_info['vertices'][0]
self.atom_types += BB_T3_A.atom_types
vertice_pos = np.array(vertice_data['position'])*a
R_Matrix = R.from_euler('z',
vertice_data['angle'],
degrees=True).as_matrix()
rotated_pos = np.dot(BB_T3_A.atom_pos, R_Matrix) + vertice_pos
self.atom_pos += rotated_pos.tolist()
self.atom_labels += ['C1' if i == 'C' else i for i in BB_T3_A.atom_labels]
# Add the A2 building block to the structure
vertice_data = topology_info['vertices'][1]
self.atom_types += BB_T3_B.atom_types
vertice_pos = np.array(vertice_data['position'])*a
R_Matrix = R.from_euler('z',
vertice_data['angle'],
degrees=True).as_matrix()
rotated_pos = np.dot(BB_T3_B.atom_pos, R_Matrix) + vertice_pos
self.atom_pos += rotated_pos.tolist()
self.atom_labels += ['C2' if i == 'C' else i for i in BB_T3_B.atom_labels]
# Creates a pymatgen structure
StartingFramework = Structure(
self.cellMatrix,
self.atom_types,
self.atom_pos,
coords_are_cartesian=True,
site_properties={'source': self.atom_labels}
).get_sorted_structure()
# Translates the structure to the center of the cell
StartingFramework.translate_sites(
range(len(StartingFramework.as_dict()['sites'])),
[0, 0, 0.5],
frac_coords=True,
to_unit_cell=True)
dict_structure = StartingFramework.as_dict()
self.cellMatrix = np.array(dict_structure['lattice']['matrix']).astype(float)
self.cellParameters = cell_to_cellpar(self.cellMatrix)
self.atom_types = [i['label'] for i in dict_structure['sites']]
self.atom_pos = [i['xyz'] for i in dict_structure['sites']]
self.atom_labels = [i['properties']['source'] for i in dict_structure['sites']]
if stacking == 'A' or stacking == 'AA':
stacked_structure = StartingFramework
if stacking == 'AB1':
self.cellMatrix *= (1, 1, 2)
self.cellParameters *= (1, 1, 2, 1, 1, 1)
self.atom_types = np.concatenate((self.atom_types, self.atom_types))
self.atom_pos = np.concatenate((self.atom_pos, self.atom_pos))
self.atom_labels = np.concatenate((self.atom_labels, self.atom_labels))
stacked_structure = Structure(
self.cellMatrix,
self.atom_types,
self.atom_pos,
coords_are_cartesian=True,
site_properties={'source': self.atom_labels}
)
# Get the index of the atoms in the second sheet
B_list = np.split(np.arange(len(self.atom_types)), 2)[1]
# Translate the second sheet by the vector [2/3, 1/3, 0.5] to generate the B positions
stacked_structure.translate_sites(
B_list,
[2/3, 1/3, 0.5],
frac_coords=True,
to_unit_cell=True
)
if stacking == 'AB2':
self.cellMatrix *= (1, 1, 2)
self.cellParameters *= (1, 1, 2, 1, 1, 1)
self.atom_types = np.concatenate((self.atom_types, self.atom_types))
self.atom_pos = np.concatenate((self.atom_pos, self.atom_pos))
self.atom_labels = np.concatenate((self.atom_labels, self.atom_labels))
stacked_structure = Structure(
self.cellMatrix,
self.atom_types,
self.atom_pos,
coords_are_cartesian=True,
site_properties={'source': self.atom_labels}
)
# Get the index of the atoms in the second sheet
B_list = np.split(np.arange(len(self.atom_types)), 2)[1]
# Translate the second sheet by the vector [1/2, 0, 0.5] to generate the B positions
stacked_structure.translate_sites(
B_list,
[1/2, 0, 0.5],
frac_coords=True,
to_unit_cell=True
)
if stacking == 'ABC1':
self.cellMatrix *= (1, 1, 3)
self.cellParameters *= (1, 1, 3, 1, 1, 1)
self.atom_types = np.concatenate((self.atom_types, self.atom_types, self.atom_types))
self.atom_pos = np.concatenate((self.atom_pos, self.atom_pos, self.atom_pos))
self.atom_labels = np.concatenate((self.atom_labels, self.atom_labels, self.atom_labels))
stacked_structure = Structure(
self.cellMatrix,
self.atom_types,
self.atom_pos,
coords_are_cartesian=True,
site_properties={'source': self.atom_labels}
)
# Get the index of the atoms in the second sheet
_, B_list, C_list = np.split(np.arange(len(self.atom_types)), 3)
# Translate the second sheet by the vector (2/3, 1/3, 0) to generate the B positions
stacked_structure.translate_sites(
B_list,
(2/3, 1/3, 1/3),
frac_coords=True,
to_unit_cell=True
)
# Translate the third sheet by the vector (2/3, 1/3, 0) to generate the B positions
stacked_structure.translate_sites(
C_list,
(4/3, 2/3, 2/3),
frac_coords=True,
to_unit_cell=True
)
if stacking == 'ABC2':
self.cellMatrix *= (1, 1, 3)
self.cellParameters *= (1, 1, 3, 1, 1, 1)
self.atom_types = np.concatenate((self.atom_types, self.atom_types, self.atom_types))
self.atom_pos = np.concatenate((self.atom_pos, self.atom_pos, self.atom_pos))
self.atom_labels = np.concatenate((self.atom_labels, self.atom_labels, self.atom_labels))
stacked_structure = Structure(
self.cellMatrix,
self.atom_types,
self.atom_pos,
coords_are_cartesian=True,
site_properties={'source': self.atom_labels}
)
# Get the index of the atoms in the second sheet
_, B_list, C_list = np.split(np.arange(len(self.atom_types)), 3)
# Translate the second sheet by the vector (2/3, 1/3, 0) to generate the B positions
stacked_structure.translate_sites(
B_list,
(1/3, 0, 1/3),
frac_coords=True,
to_unit_cell=True
)
# Translate the third sheet by the vector (2/3, 1/3, 0) to generate the B positions
stacked_structure.translate_sites(
C_list,
(2/3, 0, 2/3),
frac_coords=True,
to_unit_cell=True
)
if stacking == 'AAl':
self.cellMatrix *= (1, 1, 2)
self.cellParameters *= (1, 1, 2, 1, 1, 1)
self.atom_types = np.concatenate((self.atom_types, self.atom_types))
sv = np.array(shift_vector)
self.atom_pos = np.concatenate((self.atom_pos, self.atom_pos + sv))
self.atom_labels = np.concatenate((self.atom_labels, self.atom_labels))
stacked_structure = Structure(
self.cellMatrix,
self.atom_types,
self.atom_pos,
coords_are_cartesian=True,
site_properties={'source': self.atom_labels}
)
# Get the index of the atoms in the second sheet
B_list = np.split(np.arange(len(self.atom_types)), 2)[1]
# Translate the second sheet by the vector [2/3, 1/3, 0.5] to generate the B positions
stacked_structure.translate_sites(
B_list,
[0, 0, 0.5],
frac_coords=True,
to_unit_cell=True
)
# Create AA tilted stacking.
if stacking == 'AAt':
cell = StartingFramework.as_dict()['lattice']
# Shift the cell by the tilt angle
a_cell = cell['a']
b_cell = cell['b']
c_cell = cell['c'] * 2
alpha = cell['alpha'] - tilt_angle
beta = cell['beta'] - tilt_angle
gamma = cell['gamma']
self.cellMatrix = cellpar_to_cell([a_cell, b_cell, c_cell, alpha, beta, gamma])
self.cellParameters = np.array([a_cell, b_cell, c_cell, alpha, beta, gamma]).astype(float)
self.atom_types = np.concatenate((self.atom_types, self.atom_types))
self.atom_pos = np.concatenate((self.atom_pos, self.atom_pos))
self.atom_labels = np.concatenate((self.atom_labels, self.atom_labels))
stacked_structure = Structure(
self.cellMatrix,
self.atom_types,
self.atom_pos,
coords_are_cartesian=True,
site_properties={'source': self.atom_labels}
)
# Get the index of the atoms in the second sheet
B_list = np.split(np.arange(len(self.atom_types)), 2)[1]
# Translate the second sheet by the vector [2/3, 1/3, 0.5] to generate the B positions
stacked_structure.translate_sites(
B_list,
[0, 0, 0.5],
frac_coords=True,
to_unit_cell=True
)
dict_structure = stacked_structure.as_dict()
self.cellMatrix = np.array(dict_structure['lattice']['matrix']).astype(float)
self.cellParameters = cell_to_cellpar(self.cellMatrix)
self.atom_types = [i['label'] for i in dict_structure['sites']]
self.atom_pos = [i['xyz'] for i in dict_structure['sites']]
self.atom_labels = [i['properties']['source'] for i in dict_structure['sites']]
self.n_atoms = len(dict_structure['sites'])
self.composition = stacked_structure.formula
dist_matrix = StartingFramework.distance_matrix
# Check if there are any atoms closer than 0.8 A
for i in range(len(dist_matrix)):
for j in range(i+1, len(dist_matrix)):
if dist_matrix[i][j] < self.dist_threshold:
raise BondLenghError(i, j, dist_matrix[i][j], self.dist_threshold)
# Get the simmetry information of the generated structure
symm = SpacegroupAnalyzer(stacked_structure,
symprec=self.symm_tol,
angle_tolerance=self.angle_tol)
try:
self.prim_structure = symm.get_refined_structure(keep_site_properties=True)
self.logger.debug(self.prim_structure)
self.lattice_type = symm.get_lattice_type()
self.space_group = symm.get_space_group_symbol()
self.space_group_n = symm.get_space_group_number()
symm_op = symm.get_point_group_operations()
self.hall = symm.get_hall()
except Exception as e:
self.logger.exception(e)
self.lattice_type = 'Triclinic'
self.space_group = 'P1'
self.space_group_n = '1'
symm_op = [1]
self.hall = 'P 1'
symm_text = get_framework_symm_text(self.name,
str(self.lattice_type),
str(self.hall[0:2]),
str(self.space_group),
str(self.space_group_n),
len(symm_op))
self.logger.info(symm_text)
return [self.name,
str(self.lattice_type),
str(self.hall[0:2]),
str(self.space_group),
str(self.space_group_n),
len(symm_op)]
def create_hcb_a_structure(self,
BB_T3: str,
BB_L2: str,
stacking: str = 'AA',
slab: float = 10.0,
shift_vector: list = (1.0, 1.0, 0),
tilt_angle: float = 5.0):
"""Creates a COF with HCB-A network.
The HCB-A net is composed of one tripodal and one linear building blocks.
Parameters
----------
BB_T3 : BuildingBlock, required
The BuildingBlock object of the tripodal Buiding Block
BB_L2 : BuildingBlock, required
The BuildingBlock object of the linear Buiding Block
stacking : str, optional
The stacking pattern of the COF layers (default is 'AA')
c_parameter_base : float, optional
The base value for interlayer distance in angstroms (default is 3.6)
print_result : bool, optional
Parameter for the control for printing the result (default is True)
slab : float, optional
Default parameter for the interlayer slab (default is 10.0)
shift_vector: list, optional
Shift vector for the AAl and AAt stakings (defatult is [1.0,1.0,0])
tilt_angle: float, optional
Tilt angle for the AAt staking in degrees (default is 5.0)
Returns
-------
list
A list of strings containing:
1. the structure name
2. lattice type
3. hall symbol of the cristaline structure
4. space group
5. number of the space group,
6. number of operation symmetry
"""
connectivity_error = 'Building block {} must present connectivity {} not {}'
if BB_T3.connectivity != 3:
self.logger.error(connectivity_error.format('A', 3, BB_T3.connectivity))
raise BBConnectivityError(3, BB_T3.connectivity)
if BB_L2.connectivity != 2:
self.logger.error(connectivity_error.format('B', 3, BB_L2.connectivity))
raise BBConnectivityError(2, BB_L2.connectivity)
self.name = f'{BB_T3.name}-{BB_L2.name}-HCB_A-{stacking}'
self.topology = 'HCB_A'
self.staking = stacking
self.dimension = 2
self.charge = BB_L2.charge + BB_T3.charge
self.chirality = BB_L2.chirality or BB_T3.chirality
self.logger.debug(f'Starting the creation of {self.name}')
# Detect the bond atom from the connection groups type
bond_atom = get_bond_atom(BB_T3.conector, BB_L2.conector)
self.logger.debug('{} detected as bond atom for groups {} and {}'.format(bond_atom,
BB_T3.conector,
BB_L2.conector))
# Replace "X" the building block
BB_L2.replace_X(bond_atom)
# Remove the "X" atoms from the the building block
BB_T3.remove_X()
BB_L2.remove_X()