Coverage for cclib/bridge/cclib2pyquante.py : 86%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2#
3# Copyright (c) 2020, the cclib development team
4#
5# This file is part of cclib (http://cclib.github.io) and is distributed under
6# the terms of the BSD 3-Clause License.
8"""Bridge for using cclib data in PyQuante (http://pyquante.sourceforge.net)."""
10import numpy
11from cclib.parser.utils import find_package
14class MissingAttributeError(Exception):
15 pass
18_found_pyquante2 = find_package("pyquante2")
19if _found_pyquante2:
20 from pyquante2 import molecule
23def _check_pyquante():
24 if not _found_pyquante2:
25 raise ImportError("You must install `pyquante2` to use this function")
28def makepyquante(data):
29 """Create a PyQuante Molecule from ccData object."""
30 _check_pyquante()
32 # Check required attributes.
33 required_attrs = {"atomcoords", "atomnos"}
34 missing = [x for x in required_attrs if not hasattr(data, x)]
36 if missing:
37 missing = " ".join(missing)
38 raise MissingAttributeError(
39 "Could not create pyquante molecule due to missing attribute: {}".format(missing)
40 )
42 # In pyquante2, molecular geometry is specified in a format of:
43 # [(3,.0000000000, .0000000000, .0000000000), (1, .0000000000, .0000000000,1.629912)]
44 moldesc = numpy.insert(data.atomcoords[-1], 0, data.atomnos, 1).tolist()
46 return molecule(
47 [tuple(x) for x in moldesc],
48 units="Angstroms",
49 charge=data.charge,
50 multiplicity=data.mult,
51 )
54del find_package