11import click , os
2- from . import cp2k_input_parsing
2+ from ase .io import read
3+ import numpy as np
4+ from ase .collections import g2
5+ from mdkits .util import os_operation , cp2k_input_parsing , out_err
36
47
58class CellType (click .ParamType ):
@@ -8,16 +11,17 @@ class CellType(click.ParamType):
811 def convert (self , value , param , ctx ):
912 if isinstance (value , str ):
1013 if ',' not in value :
11- cell = cp2k_input_parsing .parse_cell (value )
14+ cell = cp2k_input_parsing .parse_cell ()
1215 return cell
1316 else :
1417 cell = [float (x ) for x in value .split (',' )]
1518
1619 if len (cell ) == 3 :
17- click .echo (f"system cell: x = { cell [0 ]} , y = { cell [1 ]} , z = { cell [2 ]} , a = { 90 } \u00B0 , b = { 90 } \u00B0 , c = { 90 } \u00B0 " )
18- return cell + [90 , 90 , 90 ]
20+ cell += [90 , 90 , 90 ]
21+ out_err .cell_output (cell )
22+ return cell
1923 elif len (cell ) == 6 :
20- click . echo ( f"system cell: x = { cell [ 0 ] } , y = { cell [ 1 ] } , z = { cell [ 2 ] } , a = { cell [ 3 ] } \u00B0 , b = { cell [ 4 ] } \u00B0 , c = { cell [ 5 ] } \u00B0 " )
24+ out_err . cell_output ( cell )
2125 return cell
2226 else :
2327 self .fail (f"{ value } is not a valid cell parameter" , param , ctx )
@@ -37,16 +41,45 @@ def convert(self, value, param, ctx):
3741 self .fail (f"{ value } is not a valid frame range" , param , ctx )
3842
3943
40- from ase .collections import g2
44+ class StructureType (click .ParamType ):
45+ name = "structure file type"
46+ def convert (self , value , param , ctx ):
47+ no_cell = np .array ([0. , 0. , 0. , 90. , 90. , 90. ])
48+ if isinstance (value , str ):
49+ if os .path .exists (value ):
50+ try :
51+ atoms = read (value )
52+ except :
53+ self .fail (f"{ value } is not a valid structure file" , param , ctx )
54+
55+ if np .array_equal (atoms .cell .cellpar (), no_cell ):
56+ cell = cp2k_input_parsing .parse_cell ()
57+ atoms .set_cell (cell )
58+
59+ return atoms
60+ else :
61+ self .fail (f"{ value } is not exists" , param , ctx )
62+
63+
64+
4165class MoleculeType (click .Choice ):
4266 name = "mocular type"
4367 def __init__ (self ):
4468 super ().__init__ (self )
4569 g2 .names .append (click .Path (exists = True ))
4670 self .choices = tuple (g2 .names )
4771
72+ class AdsSiteType (click .Choice ):
73+ name = "adsorption site"
74+ def __init__ (self ):
75+ super ().__init__ (self )
76+ site = ['ontop' , 'hollow' ,'fcc' , 'hcp' , 'bridge' , 'shortbridge' , 'longbridge' ]
77+ self .choices = tuple (site )
78+
4879
4980
5081Cell = CellType ()
5182FrameRange = FrameRangeType ()
5283Molecule = MoleculeType ()
84+ AdsSite = AdsSiteType ()
85+ Structure = StructureType ()
0 commit comments