orto 1.0.6__py3-none-any.whl → 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
orto/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = '1.0.6'
1
+ __version__ = '1.2.0'
orto/cli.py CHANGED
@@ -464,7 +464,7 @@ def gen_job_func(uargs):
464
464
 
465
465
  # Check xyz file is present
466
466
  try:
467
- inp.check_xyz(oj.input_file, uargs.skip_xyz)
467
+ inp.check_coord(oj.input_file, uargs.skip_xyz)
468
468
  except (DataNotFoundError, DataFormattingError) as e:
469
469
  ut.red_exit(str(e))
470
470
 
@@ -504,6 +504,28 @@ def gen_job_func(uargs):
504
504
  # Use orca file value
505
505
  config['mem_per_cpu'] = maxcore
506
506
 
507
+ # Check if NBO is requested
508
+ if inp.get_nbo(oj.input_file):
509
+ # Check if NBO module has been provided to orto
510
+ try:
511
+ if os.getenv('orto_nbo_load') is not None:
512
+ nbo_module = os.getenv('orto_nbo_load')
513
+ else:
514
+ ut.red_exit(
515
+ 'Missing orto_nbo_load environment variable'
516
+ )
517
+ except ValueError:
518
+ ut.red_exit(
519
+ (
520
+ 'Missing or malformed orto_nbo_load'
521
+ 'environment variable'
522
+ )
523
+ )
524
+ oj.pre_orca += f'module load {nbo_module}\n'
525
+ oj.pre_orca += f'export NBOFIL={oj.input_file.stem}\n'
526
+ else:
527
+ nbo_module = None
528
+
507
529
  # Set SLURM error and output file names
508
530
  config['error'] = 'slurm.%j.e'
509
531
  config['output'] = 'slurm.%j.o'
@@ -835,9 +857,22 @@ def extract_orbs_func(uargs, save=True) -> None:
835
857
  dtype=int
836
858
  )
837
859
  ])
860
+ elif uargs.num is not None:
861
+ keep = uargs.num
838
862
  else:
839
863
  keep = range(len(contributions))
840
864
 
865
+ # Remove orbital indices which do not exist
866
+ keep = [val for val in keep if val < len(contributions)]
867
+
868
+ if not len(keep):
869
+ ut.red_exit(
870
+ (
871
+ r'Selected orbital indices do not exist!'
872
+ f'\nNORBS = {len(contributions):d}'
873
+ )
874
+ )
875
+
841
876
  contributions = contributions.loc[:, keep]
842
877
 
843
878
  # Remove contributions from unwanted orbitals
@@ -2058,13 +2093,37 @@ def read_args(arg_list=None):
2058
2093
  )
2059
2094
  )
2060
2095
 
2096
+ def gte_zero(x):
2097
+ '''
2098
+ Custom type for argparse to ensure that the input
2099
+ \nis greater than or equal to zero
2100
+ '''
2101
+ value = int(x)
2102
+ if value < 0:
2103
+ raise argparse.ArgumentTypeError(
2104
+ f'{x} is not a valid index (must be >= 0)'
2105
+ )
2106
+ return value
2107
+
2108
+ orb_group.add_argument(
2109
+ '-n',
2110
+ '--num',
2111
+ nargs='+',
2112
+ type=gte_zero,
2113
+ metavar='NUMBER',
2114
+ default=None,
2115
+ help=(
2116
+ 'Print specified orbitals using index starting from 0\n'
2117
+ '(same as Orca)\n'
2118
+ )
2119
+ )
2120
+
2061
2121
  orb_group.add_argument(
2062
2122
  '-hl',
2063
2123
  '--homo_lumo',
2064
2124
  nargs='?',
2065
2125
  type=int,
2066
2126
  metavar='NUMBER',
2067
- const=0,
2068
2127
  default=None,
2069
2128
  help=(
2070
2129
  'Print specified number of orbitals either side of HOMO and LUMO'
orto/extractor.py CHANGED
@@ -1880,7 +1880,7 @@ class MOInpExtractor(extto.LineExtractor):
1880
1880
 
1881
1881
  class XYZInputExtractor(extto.LineExtractor):
1882
1882
  '''
1883
- Extracts .xyz line of an input file
1883
+ Extracts *xyz line of an input file
1884
1884
 
1885
1885
  *xyz charge multiplicity
1886
1886
  '''
@@ -1936,6 +1936,26 @@ class XYZInputExtractor(extto.LineExtractor):
1936
1936
  return _ext.data
1937
1937
 
1938
1938
 
1939
+ class IntInputExtractor(XYZInputExtractor):
1940
+ '''
1941
+ Extracts *int line of an input file
1942
+
1943
+ *int charge multiplicity
1944
+ '''
1945
+
1946
+ # Regex pattern for line
1947
+ PATTERN = rb'\* *int *-?\d+ *\d'
1948
+
1949
+ MODIFIERS = [re.IGNORECASE]
1950
+
1951
+ @property
1952
+ def data(self) -> list[str]:
1953
+ '''
1954
+ *int line, one entry per match
1955
+ '''
1956
+ return self._data
1957
+
1958
+
1939
1959
  class MaxCoreInputExtractor(extto.LineExtractor):
1940
1960
  '''
1941
1961
  Extracts maxcore from input file\n
@@ -2006,7 +2026,7 @@ class SimpleInputExtractor(extto.LineExtractor):
2006
2026
  # Regex pattern for line
2007
2027
  PATTERN = rb'^ *!.*'
2008
2028
 
2009
- MODIFIERS = [re.IGNORECASE]
2029
+ MODIFIERS = [re.IGNORECASE, re.MULTILINE]
2010
2030
 
2011
2031
  @property
2012
2032
  def data(self) -> list[str]:
orto/input.py CHANGED
@@ -9,6 +9,45 @@ from . import extractor as oe
9
9
  from . import utils as ut
10
10
 
11
11
 
12
+ def get_nbo(file_name: str | Path) -> bool:
13
+ '''
14
+ Check if NBO is present in the simple input line.\n
15
+
16
+ Parameters
17
+ ----------
18
+ file_name: str | Path
19
+ Orca input file as either name or Path object
20
+
21
+ Returns
22
+ -------
23
+ bool
24
+ True if NBO is present, False otherwise
25
+ '''
26
+ # Check for simple input line beginning with !
27
+ try:
28
+ simple = oe.SimpleInputExtractor.extract(file_name)
29
+ except DataNotFoundError:
30
+ ut.red_exit(
31
+ 'Error: Missing simple input line (or !) in input file'
32
+ )
33
+ # Check for NBO in simple input
34
+ nbo_simple = re.findall(
35
+ r'NBO',
36
+ simple[0],
37
+ flags=re.IGNORECASE
38
+ )
39
+ if len(nbo_simple):
40
+ # Set to True if found
41
+ if nbo_simple is None:
42
+ _nbo = True
43
+ else:
44
+ _nbo = True
45
+ else:
46
+ _nbo = False
47
+
48
+ return _nbo
49
+
50
+
12
51
  def get_nprocs(file_name: str | Path) -> int:
13
52
  '''
14
53
  Get the number of processors from the input file.\n
@@ -124,6 +163,81 @@ def get_maxcore(file_name: str | Path) -> int:
124
163
  return maxcore
125
164
 
126
165
 
166
+ def check_coord(file_name: str | Path, skip_check) -> None:
167
+ '''
168
+ Check *xyz, *xyzfile, or *int line is present in input file.\n
169
+ If xyzfile is given, then also checks if this exists and is formatted \n
170
+ correctly.\n
171
+
172
+ Parameters
173
+ ----------
174
+ file_name: str | Path
175
+ Orca input file as either name or Path object
176
+ skip_check: bool
177
+ If True, skip the xyz file check
178
+
179
+ Returns
180
+ -------
181
+ None
182
+
183
+ Raises
184
+ ------
185
+ DataNotFoundError
186
+ If neither *xyzfile, *xyz, nor *int are present in the input file
187
+ DataFormattingError
188
+ If xyz file is not formatted correctly
189
+ '''
190
+
191
+ # Get xyz file name and check it exists and is formatted correctly
192
+ try:
193
+ xyz_file = oe.XYZFileInputExtractor.extract(file_name)
194
+ except DataNotFoundError:
195
+ xyz_file = []
196
+
197
+ try:
198
+ xyzline = oe.XYZInputExtractor.extract(file_name)
199
+ except DataNotFoundError:
200
+ xyzline = []
201
+
202
+ try:
203
+ intline = oe.IntInputExtractor.extract(file_name)
204
+ except DataNotFoundError:
205
+ intline = []
206
+
207
+ lens = [len(xyz_file), len(xyzline), len(intline)]
208
+
209
+ if not sum(lens):
210
+ ut.red_exit(
211
+ 'Error: missing or incorrect *xyzfile or *xyz line in input'
212
+ )
213
+ elif sum(lens) > 1:
214
+ ut.red_exit(
215
+ (
216
+ 'Error: multiple *xyzfile or *xyz lines in input.\n'
217
+ 'Only one can be present'
218
+ )
219
+ )
220
+
221
+ if len(xyz_file):
222
+ xyz_file = Path(xyz_file[0])
223
+ if not xyz_file.is_file():
224
+ ut.red_exit(
225
+ 'Error: xyz file specified in input cannot be found'
226
+ )
227
+
228
+ if not skip_check:
229
+ try:
230
+ xyzp.check_xyz(
231
+ xyz_file.absolute(),
232
+ allow_indices=False
233
+ )
234
+ except xyzp.XYZError as e:
235
+ raise DataFormattingError(
236
+ f'{e}\n Use -sx to skip this check at your peril'
237
+ )
238
+ return
239
+
240
+
127
241
  def check_xyz(file_name: str | Path, skip_check) -> None:
128
242
  '''
129
243
  Check *xyz or *xyzfile line is present in input file.\n
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orto
3
- Version: 1.0.6
3
+ Version: 1.2.0
4
4
  Summary: A package to make life easier when performing Orca calculations.
5
5
  Home-page: https://orto.kragskow.group
6
6
  Author: Jon Kragskow
@@ -15,7 +15,7 @@ Description-Content-Type: text/markdown
15
15
  Requires-Dist: numpy>=2.1.2
16
16
  Requires-Dist: xyz_py>=5.13.1
17
17
  Requires-Dist: matplotlib>=3.9.2
18
- Requires-Dist: extto>=0.5.0
18
+ Requires-Dist: extto>=1.0.1
19
19
  Requires-Dist: pandas>=2.2.3
20
20
  Requires-Dist: subto>=0.1.1
21
21
  Requires-Dist: python-docx>=1.1.2
@@ -0,0 +1,15 @@
1
+ orto/__init__.py,sha256=IedlltYr3qYZxChNUdz62qogXA9Pos_MUvXdGXqAa0E,41
2
+ orto/__version__.py,sha256=U3f_Jgr3zpgiYG2kLcvcT05TQsVzN9Kktg_f3Q9OZFA,22
3
+ orto/cli.py,sha256=AJEQtMXw4uODLZpTgiBu3jz5l6VDU9kSWc5r3e0Zxss,63122
4
+ orto/constants.py,sha256=2obWYg306Lce4U9Qs4MHg1yZq7SHFkazG-cnkD5svpo,343
5
+ orto/exceptions.py,sha256=D7oNeAEGeJNt5thzt6PaCn5FY6JcbJOWUE1N1LVhhuE,159
6
+ orto/extractor.py,sha256=aeZK130lBIERS4Pj1jvTlxCwVB_AhFLUB16zQrDhcbM,67767
7
+ orto/input.py,sha256=N8JbySSVEC_qmXZ7ppJsZ7Z1qel6PfalGYRtnX1hJ6U,9900
8
+ orto/job.py,sha256=SM0nlc_bqhhPvfuuykhMvaUnkwC3Gp-6RvYw_a0TyGc,5855
9
+ orto/plotter.py,sha256=ICrO03T_HGe-H1XKZ2qzsKYdPY44E0PKiXqIQQawd7I,15633
10
+ orto/utils.py,sha256=gVfGplkfc6xGYgLMi_7I_yAdWG-QKRaqQdy9v5F4Mck,7279
11
+ orto-1.2.0.dist-info/METADATA,sha256=rH_vzAEMyJpQc9mJ_3T_q8OeielkInXjdfxrQwIWGdE,1140
12
+ orto-1.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ orto-1.2.0.dist-info/entry_points.txt,sha256=HXenCglMp_03JkN34pK2phkjXK9CFcXTGHKv5QaVY8I,39
14
+ orto-1.2.0.dist-info/top_level.txt,sha256=hQ-z28gTN_FZ2B5Kiwxr_9cUTcCoib9W5HjbkceDXw4,5
15
+ orto-1.2.0.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- orto/__init__.py,sha256=IedlltYr3qYZxChNUdz62qogXA9Pos_MUvXdGXqAa0E,41
2
- orto/__version__.py,sha256=iNeZ6LZ9iCV_ugsqAh5K1fFqbKkfU8o3NbLYBWI3m1I,22
3
- orto/cli.py,sha256=S05ypFp4NEv1ZVaa4xTSz_oTrAeVwpL1rd8qNRviz8A,61349
4
- orto/constants.py,sha256=2obWYg306Lce4U9Qs4MHg1yZq7SHFkazG-cnkD5svpo,343
5
- orto/exceptions.py,sha256=D7oNeAEGeJNt5thzt6PaCn5FY6JcbJOWUE1N1LVhhuE,159
6
- orto/extractor.py,sha256=tO2oFf6Cgwdnh_m1v8r1rXQO2_FL7s-1KBqLPy6zNco,67384
7
- orto/input.py,sha256=DGWG0IQ_QS9RCm4BlgFPyt4_WW6Tz9k2Mybwd1O9SJo,7003
8
- orto/job.py,sha256=SM0nlc_bqhhPvfuuykhMvaUnkwC3Gp-6RvYw_a0TyGc,5855
9
- orto/plotter.py,sha256=ICrO03T_HGe-H1XKZ2qzsKYdPY44E0PKiXqIQQawd7I,15633
10
- orto/utils.py,sha256=gVfGplkfc6xGYgLMi_7I_yAdWG-QKRaqQdy9v5F4Mck,7279
11
- orto-1.0.6.dist-info/METADATA,sha256=CxH6biskRO90R3ezsXOGAQiViTuYV0uRWnoTQ6PrnYw,1140
12
- orto-1.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- orto-1.0.6.dist-info/entry_points.txt,sha256=HXenCglMp_03JkN34pK2phkjXK9CFcXTGHKv5QaVY8I,39
14
- orto-1.0.6.dist-info/top_level.txt,sha256=hQ-z28gTN_FZ2B5Kiwxr_9cUTcCoib9W5HjbkceDXw4,5
15
- orto-1.0.6.dist-info/RECORD,,
File without changes