1111# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212# See the License for the specific language governing permissions and
1313# limitations under the License.
14+ """
15+ Lightweight ``mole`` module.
16+ """
1417
1518from __future__ import annotations
16- from typing import Any
1719from collections .abc import Callable
1820import contextlib
1921
4648 is_au ,
4749)
4850
51+ from pyscfad .typing import ArrayLike , Array
4952from pyscfad import numpy as np
5053from pyscfad import ops
5154from pyscfad .gto .mole import energy_nuc
5255from pyscfad .gto import moleintor_lite
5356
54- Array = Any
55-
5657def _format_basis (basis , uniq_symbols ):
5758 if isinstance (basis , dict ):
5859 for k , v in basis .items ():
@@ -85,44 +86,32 @@ def _format_symbols(symbols):
8586 symbols = [symbols ,]
8687 return tuple (_atom_symbol (symb ) for symb in symbols )
8788
88- class Mole (MoleBase ):
89- """Molecular information.
90-
91- Parameters
92- ----------
93- symbols : tuple of str
94- Atomic symbols (mutually exclusive with ``numbers``).
95- coords : array
96- Atomic coordinates (in Bohr).
97- basis : dict or str
98- A string indicating the Gaussian basis set to use, or
99- a dictionary including the basis set parameters
100- (exponents and contraction coefficients).
101- numbers : tuple of ints
102- Atomic numbers (mutually exclusive with ``symbols``).
103- charge : int
104- Total charge.
105- spin : int
106- 2S (number of alpha electrons minus number of beta electrons).
107- cart : bool
108- Whether to use Cartesian Gaussian basis.
109- verbose : int
110- Printing level.
111- trace_coords : bool
112- Whether to trace atomic coordinates for gradient calculations.
113- trace_basis : bool
114- Whether to trace basis set parameters for gradient calculations.
115-
116- Notes
117- -----
118- The molecular composition (i.e., ``symbols`` or ``numbers``)
119- must be static as input. For dynamic molecular composition,
120- refer to :class:`pyscfad.ml.gto.MolePad`.
89+ class MoleLite (MoleBase ):
90+ """Molecular information (lightweight version).
91+
92+ Parameters:
93+ symbols: Atomic symbols (mutually exclusive with ``numbers``).
94+ coords: Atomic coordinates (in Bohr).
95+ basis: A string indicating the Gaussian basis set to use, or
96+ a dictionary including the basis set parameters
97+ (exponents and contraction coefficients).
98+ numbers: Atomic numbers (mutually exclusive with ``symbols``).
99+ charge: Total charge.
100+ spin: 2S (number of alpha electrons minus number of beta electrons).
101+ cart: Whether to use Cartesian Gaussian basis.
102+ verbose: Printing level.
103+ trace_coords: Whether to trace atomic coordinates for gradient calculations.
104+ trace_basis: Whether to trace basis set parameters for gradient calculations.
105+
106+ Notes:
107+ The molecular composition (i.e., ``symbols`` or ``numbers``)
108+ must be static as input. For dynamic molecular composition,
109+ refer to :class:`~pyscfad.ml.gto.mole_pad.MolePad`.
121110 """
122111 def __init__ (
123112 self ,
124113 symbols : tuple [str , ...] | None = None ,
125- coords : Array | None = None ,
114+ coords : ArrayLike | None = None ,
126115 basis : dict | str | None = None ,
127116 numbers : tuple [int , ...] | None = None ,
128117 charge : int = 0 ,
@@ -171,7 +160,12 @@ def atom_pure_symbol(
171160 def atom_coords (
172161 self ,
173162 unit : str = "Bohr" ,
174- ):
163+ ) -> Array :
164+ """Atom coordinates.
165+
166+ Parameters:
167+ unit: Units of returned coordinates, can be ``Bohr`` or ``Angstrom``.
168+ """
175169 if not is_au (unit ):
176170 return self .coords * BOHR
177171 else :
@@ -180,7 +174,7 @@ def atom_coords(
180174 def copy (
181175 self ,
182176 deep : bool = True ,
183- ) -> Mole :
177+ ) -> MoleLite :
184178 import copy
185179 newmol = self .view (self .__class__ )
186180 if not deep :
@@ -193,7 +187,10 @@ def copy(
193187 newmol ._env = np .copy (self ._env )
194188 return newmol
195189
196- def build (self , * args , ** kwargs ):
190+ def build (self , * args , ** kwargs ) -> MoleLite :
191+ """Placeholder for post-init processing.
192+ Can be used for caching one-time computed quantities.
193+ """
197194 return self
198195
199196 def intor (
@@ -202,10 +199,32 @@ def intor(
202199 comp : int | None = None ,
203200 hermi : int = 0 ,
204201 aosym : str = "s1" ,
205- out : Array | None = None ,
202+ out : ArrayLike | None = None ,
206203 shls_slice : tuple [int , ...] | None = None ,
207- grids : Array | None = None ,
204+ grids : ArrayLike | None = None ,
208205 ) -> Array :
206+ """Integral generator.
207+
208+ Parameters:
209+ intor_name: Name of the integral.
210+ comp: Components of the integrals, e.g. ``int1e_ovlp_dr10`` has 3 components.
211+ hermi: Hermitian symmetry of 1e integrals, can be
212+ `0` (no symmetry), `1` (hermitian), and `2` (anti-hermitian).
213+ aosym: Permutation symmetry of 2e integrals, can be
214+ `s1`, `s2`, `s4`, and `s8`.
215+ out: Not used.
216+ shls_slice: Label the start-stop shells for each index in the integral.
217+ For example, the 8-element tuple for the 2e integral
218+ tensor ``(ij|kl) = intor('int2e')`` are specified as
219+ ``(i0, i1, j0, j1, k0, k1, l0, l1)``.
220+ grids: Not used.
221+
222+ Returns:
223+ Computed integral as an array.
224+
225+ See also:
226+ :func:`pyscf.gto.Mole.intor`
227+ """
209228 del out , grids
210229
211230 intor_name = self ._add_suffix (intor_name )
@@ -230,8 +249,8 @@ def intor(
230249
231250 def set_common_origin (
232251 self ,
233- coord : Array ,
234- ) -> Mole :
252+ coord : ArrayLike ,
253+ ) -> MoleLite :
235254 if self ._env is None :
236255 raise RuntimeError ("{self}._env is not initialized, "
237256 "possibly because basis is not set." )
@@ -245,15 +264,15 @@ def set_common_origin(
245264
246265 def with_common_origin (
247266 self ,
248- coord : Array ,
267+ coord : ArrayLike ,
249268 ):
250269 coord0 = np .copy (self ._env [PTR_COMMON_ORIG :PTR_COMMON_ORIG + 3 ])
251270 return self ._TemporaryMoleContext (self .set_common_origin , (coord ,), (coord0 ,))
252271
253272 def set_rinv_origin (
254273 self ,
255- coord : Array ,
256- ) -> Mole :
274+ coord : ArrayLike ,
275+ ) -> MoleLite :
257276 if self ._env is None :
258277 raise RuntimeError ("{self}._env is not initialized, "
259278 "possibly because basis is not set." )
@@ -267,7 +286,7 @@ def set_rinv_origin(
267286
268287 def with_rinv_origin (
269288 self ,
270- coord : Array ,
289+ coord : ArrayLike ,
271290 ):
272291 coord0 = np .copy (self ._env [PTR_RINV_ORIG :PTR_RINV_ORIG + 3 ])
273292 return self ._TemporaryMoleContext (self .set_rinv_origin , (coord ,), (coord0 ,))
@@ -291,7 +310,9 @@ def from_pyscf(
291310 mol : MoleBase ,
292311 trace_coords : bool = False ,
293312 trace_basis : bool = False ,
294- ) -> Mole :
313+ ) -> MoleLite :
314+ """Initialize from :class:`pyscf.gto.Mole` object.
315+ """
295316 if not mol ._built :
296317 raise KeyError (f"{ mol } not built" )
297318 if mol .ecp or mol .pseudo :
@@ -327,6 +348,8 @@ def to_pyscf(
327348 output : str | None = None ,
328349 max_memory : int | None = None ,
329350 ) -> MoleBase :
351+ """Convert to :class:`pyscf.gto.Mole` object.
352+ """
330353 coords = ops .to_numpy (self .coords )
331354 atom = [[a , tuple (x .tolist ())] for a , x in zip (self .symbols , coords )]
332355
@@ -353,14 +376,13 @@ def to_pyscf(
353376
354377 energy_nuc = energy_nuc
355378
356- MoleLite = Mole
357379
358380def gaussian_int (
359381 n : int | numpy .ndarray ,
360- alpha : Array ,
382+ alpha : ArrayLike ,
361383) -> Array :
362384 r"""Gaussian integral.
363- Computes :math:`\int_0^\infty x^n exp(-alpha x^2) dx`.
385+ Computes :math:`\int_0^\infty x^n exp(-\ alpha x^2) dx`.
364386 """
365387 from pyscfad .scipy .special import gamma
366388 n1 = (n + 1 ) * .5
@@ -369,7 +391,7 @@ def gaussian_int(
369391@with_doc (pyscf .gto .mole .gto_norm .__doc__ )
370392def gto_norm (
371393 l : int | numpy .ndarray ,
372- expnt : Array ,
394+ expnt : ArrayLike ,
373395) -> Array :
374396 assert numpy .all (l >= 0 )
375397 return 1. / np .sqrt (gaussian_int (l * 2 + 2 , 2 * expnt ))
@@ -432,7 +454,7 @@ def make_bas_env(
432454 return _bas , _env
433455
434456def make_env (
435- mol : Mole ,
457+ mol : MoleLite ,
436458) -> tuple [numpy .ndarray , numpy .ndarray , Array ]:
437459 """Make ``_atm``, ``_bas``, and ``_env`` for
438460 interfacing with libcint.
0 commit comments