How to use the qcelemental.models.Molecule function in qcelemental

To help you get started, we’ve selected a few qcelemental examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MolSSI / QCEngine / qcengine / programs / nwchem / harvester.py View on Github external
lline = line.split()
                    molxyz += '%s %16s %16s %16s\n' % (lline[-5], lline[-3], lline[-2], lline[-1])
                    # Jiyoung was collecting charge (-4)? see if this is ok for ghosts
                    # Tag    ,    X,        Y,        Z
                psivar_coord = Molecule(validate=False,
                                        **qcel.molparse.to_schema(qcel.molparse.from_string(
                                            molxyz, dtype='xyz+', fix_com=True, fix_orientation=True)["qm"],
                                                                  dtype=2))

            else:  # unit = a.u.
                molxyz = '%d au\n%d %d tag\n' % (len(mobj.group(2).splitlines()), out_charge, out_mult)
                for line in mobj.group(2).splitlines():
                    lline = line.split()
                    molxyz += '%s %16s %16s %16s\n' % (int(float(lline[-4])), lline[-3], lline[-2], lline[-1])
                    # Tag    ,    X,        Y,        Z
                psivar_coord = Molecule(validate=False,
                                        **qcel.molparse.to_schema(qcel.molparse.from_string(
                                            molxyz, dtype='xyz+', fix_com=True, fix_orientation=True)["qm"],
                                                                  dtype=2))

        # Process gradient
        mobj = re.search(
            r'^\s+' + r'.*' + r'ENERGY GRADIENTS' + r'\s*' + r'\s+' + r'\n' + r'^\s+' +
            r'atom               coordinates                        gradient' + r'\s*' + r'^\s+' +
            r'x          y          z           x          y          z' + r'\s*' +
            r'((?:\s+([1-9][0-9]*)+\s+([A-Z][a-x]*)+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s*\n)+)'
            + r'\s*$', outtext, re.MULTILINE)

        if mobj:
            logger.debug('matched molgrad')
            atoms = []
            psivar_grad = []
github MolSSI / QCEngine / qcengine / programs / gamess / harvester.py View on Github external
logger.debug('matched dft xc')
            qcvar['DFT XC ENERGY'] = mobj.group(1)

        # Process Geometry
        mobj = re.search(
                r'^\s+' + r'ATOM      ATOMIC                      COORDINATES \(BOHR\)' + r'\s*' +
                r'^\s+' + r'CHARGE         X                   Y                   Z'+ r'\s*' +
                r'((?:\s+([A-Z][a-z]*)+\s+\d+\.\d+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s*\n)+)'+r'\s*$'
                , outtext, re.MULTILINE | re.IGNORECASE)
        if mobj:
            logger.debug('matched geom')
            molxyz = '%d bohr\n\n' % len(mobj.group(1).splitlines())
            for line in mobj.group(1).splitlines():
                lline = line.split()
                molxyz += '%s %16s %16s %16s\n' % (int(float(lline[-4])), lline[-3], lline[-2], lline[-1])
            qcvar_coord = Molecule(validate=False,
                                   **qcel.molparse.to_schema(qcel.molparse.from_string(molxyz,
                                                                                       dtype='xyz+',
                                                                                       fix_com=True,
                                                                                       fix_orientation=True)["qm"],
                                                             dtype=2))

        # Process Gradient
        mobj = re.search(
                r'^\s+' + r'GRADIENT OF THE ENERGY' + r'\s*'+
                r'^\s+' + r'----------------------' + r'\s*'+
                r'\s+' + r'\n'+
                r'^\s+' + r'UNITS ARE HARTREE/BOHR    E\'X               E\'Y               E\'Z' + r'\s*' +
                r'((?:\s+([1-9][0-9]*)+\s+([A-Z][a-x]*)+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s*\n)+)' +
                r'\s*$',
                outtext, re.MULTILINE)
        if mobj:
github MolSSI / QCEngine / qcengine / programs / nwchem / harvester.py View on Github external
r'((?:\s+([1-9][0-9]*)+\s+([A-Z][a-z]*)+\s+\d+\.\d+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s+[-+]?\d+\.\d+\s*\n)+)'
            + r'\s*$', outtext, re.MULTILINE | re.IGNORECASE)

        if mobj:
            logger.debug('matched geom')

            # dinky molecule w/ charge and multiplicity
            if mobj.group(1) == 'angstroms':
                molxyz = '%d \n%d %d tag\n' % (len(mobj.group(2).splitlines()), out_charge, out_mult
                                               )  # unit = angstrom
                for line in mobj.group(2).splitlines():
                    lline = line.split()
                    molxyz += '%s %16s %16s %16s\n' % (lline[-5], lline[-3], lline[-2], lline[-1])
                    # Jiyoung was collecting charge (-4)? see if this is ok for ghosts
                    # Tag    ,    X,        Y,        Z
                psivar_coord = Molecule(validate=False,
                                        **qcel.molparse.to_schema(qcel.molparse.from_string(
                                            molxyz, dtype='xyz+', fix_com=True, fix_orientation=True)["qm"],
                                                                  dtype=2))

            else:  # unit = a.u.
                molxyz = '%d au\n%d %d tag\n' % (len(mobj.group(2).splitlines()), out_charge, out_mult)
                for line in mobj.group(2).splitlines():
                    lline = line.split()
                    molxyz += '%s %16s %16s %16s\n' % (int(float(lline[-4])), lline[-3], lline[-2], lline[-1])
                    # Tag    ,    X,        Y,        Z
                psivar_coord = Molecule(validate=False,
                                        **qcel.molparse.to_schema(qcel.molparse.from_string(
                                            molxyz, dtype='xyz+', fix_com=True, fix_orientation=True)["qm"],
                                                                  dtype=2))

        # Process gradient
github hjkgrp / MultirefPredict / MultirefPredict / ebased_diagnostic.py View on Github external
return True

        # First initialize the list of dictionary for atomized molecule
        if self.molecule.molecular_charge != 0:
            raise ValueError("Logic for assigning charge and spin states for \
                    charged molecule is still under experiment.")

        for symbol in self.molecule.symbols:
            if symbol in self.atomized:
                self.atomized[symbol]["count"] += 1
            else:
                spinDict = atomSpinMultDict()
                spinmult = spinDict.get_spinmult(symbol)
                charge = 0
                geo = [0, 0, 0]
                atom = qcelemental.models.Molecule(geometry=geo,
                                                   symbols=[symbol],
                                                   molecular_charge=charge,
                                                   molecular_multiplicity=spinmult)
                self.atomized[symbol] = {"count": 1,
                                         "molecule": atom,
                                         "energy": 0
                                         }

        # Summarize the dissociation limit
        print("Dissociation limit of the molecule:")
        print("-" * 30)
        print("{:6}".format("Atom"), "{:8}".format("Count"),
              "{:8}".format("Charge"), "{:8}".format("spin"))
        print("-" * 30)
        for symbol in self.atomized:
            print("{:^6}".format(symbol), "{:^8}".format(self.atomized[symbol]["count"]),
github MolSSI / QCEngine / qcengine / mdi_server.py View on Github external
def update_molecule(self, key: str, value):
        """ Update the molecule

        Parameters
        ----------
        key : str
            Key of the molecular element to update
        value
            Update value
        """
        if key == "molecular_charge" or key == "molecular_multiplicity":
            # In order to validate correctly, the charges and multiplicities must be set simultaneously
            try:
                self.molecule = qcel.models.Molecule(
                    **{
                        **self.molecule.dict(),
                        **{
                            "molecular_charge": self.total_charge,
                            "fragment_charges": [self.total_charge],
                            "molecular_multiplicity": self.multiplicity,
                            "fragment_multiplicities": [self.multiplicity],
                        },
                    }
                )
                self.molecule_validated = True
            except qcel.exceptions.ValidationError:
                # The molecule didn't validate correctly, but a future >TOTCHARGE or >ELEC_MULT command might fix it
                self.molecule_validated = False
        else:
            try:
github MolSSI / QCEngine / qcengine / mdi_server.py View on Github external
def recv_coords(self, coords: Optional[np.ndarray] = None) -> None:
        """ Receive a set of nuclear coordinates through MDI and assign them to the atoms in the current molecule

        Parameters
        ----------
        coords : np.ndarray, optional
            New nuclear coordinates. If None, receive through MDI.
        """
        natom = len(self.molecule.geometry)
        if coords is None:
            coords = MDI_Recv(3 * natom, MDI_DOUBLE_NUMPY, self.comm)
        new_geometry = np.reshape(coords, (-1, 3))
        self.molecule = qcel.models.Molecule(**{**self.molecule.dict(), **{"geometry": new_geometry}})
github MolSSI / QCEngine / qcengine / mdi_server.py View on Github external
def update_molecule(self, key: str, value):
        """ Update the molecule

        Parameters
        ----------
        key : str
            Key of the molecular element to update
        value
            Update value
        """
        if key == "molecular_charge" or key == "molecular_multiplicity":
            # In order to validate correctly, the charges and multiplicities must be set simultaneously
            try:
                self.molecule = qcel.models.Molecule(
                    **{
                        **self.molecule.dict(),
                        **{
                            "molecular_charge": self.total_charge,
                            "fragment_charges": [self.total_charge],
                            "molecular_multiplicity": self.multiplicity,
                            "fragment_multiplicities": [self.multiplicity]
                        }
                    })
                self.molecule_validated = True
            except qcel.exceptions.ValidationError:
                # The molecule didn't validate correctly, but a future >TOTCHARGE or >ELEC_MULT command might fix it
                self.molecule_validated = False
        else:
            try:
                self.molecule = qcel.models.Molecule(**{**self.molecule.dict(), **{key: value}})
github MolSSI / QCEngine / qcengine / stock_mols.py View on Github external
def get_molecule(name):
    """
    Returns a QC JSON representation of a test molecule.
    """
    if name not in _test_mols:
        raise KeyError("Molecule name '{}' not found".format(name))

    return Molecule(**copy.deepcopy(_test_mols[name]))