Ejemplo n.º 1
0
class QChemInputGenerator(TemplateInputGenerator):
    """
    """

    property_generators = [
        PropertyGenerator(
            filename = template_dir + "basic.mako",
            property = [Energy, Gradient],
            details = ComputationDetails(
                method = (
                    # The "dotted keyword" syntax is on it's way out, since it's too confusing
                    Methods.HF, 'HF',
                    Methods.DFT, 'DFT'
                ),
                required_details = [
                    'basis'
                ],
            ),
            unsupported_details = {
                'basis' : Basis.custom_basis,
                'optimization' : True
            }
        ),
        PropertyGenerator(
            filename = template_dir + "basic.mako",
            property = [Energy, Hessian],
            details = ComputationDetails(
                method = (
                    # The "dotted keyword" syntax is on it's way out, since it's too confusing
                    Methods.HF, 'HF',
                    Methods.DFT, 'DFT'
                    ),
                required_details = [
                    'basis'
                ],
            ),
            unsupported_details = {
                'basis' : Basis.custom_basis,
                'optimization' : True
            }
        ),
        PropertyGenerator(
            filename = template_dir + "qcopt.mako",
            property = [Energy],
            details= ComputationDetails(
                method = (
                    'HF', 'DFT'
                ),
                optimization = ( True, ),
                required_details = [
                    'basis'
                ]
            ),
            unsupported_details = {
                'basis' : Basis.custom_basis,
                'optimization' : False
            }
        )
    ]
Ejemplo n.º 2
0
 def get_property_for_molecule(self, molecule, property, details=None):
     for p in self.properties_for_molecules[molecule]:
         if MolecularProperty.is_same_property(property, p):
             if ComputationDetails.is_compatible_details(details, p.details):
                 return p
     props = self.properties[molecule]
     for p in props:
         pcopy = copy(p)
         pcopy.molecule = molecule
         self.properties_for_molecules[molecule].append(pcopy)
         if MolecularProperty.is_same_property(property, p):
             if ComputationDetails.is_compatible_details(details, p.details):
                 return pcopy
     raise PropertyUnavailableError
Ejemplo n.º 3
0
 def get_property_for_molecule(self, molecule, property, details=None):
     for p in self.properties_for_molecules[molecule]:
         if MolecularProperty.is_same_property(property, p):
             if ComputationDetails.is_compatible_details(
                     details, p.details):
                 return p
     props = self.properties[molecule]
     for p in props:
         pcopy = copy(p)
         pcopy.molecule = molecule
         self.properties_for_molecules[molecule].append(pcopy)
         if MolecularProperty.is_same_property(property, p):
             if ComputationDetails.is_compatible_details(
                     details, p.details):
                 return pcopy
     raise PropertyUnavailableError
Ejemplo n.º 4
0
    def _parse_file(self, file):
        def _get_at_least_one(parent, tag, dispnum):
            ret_val = parent.findall(tag)
            if sanity_checking_enabled:
                if len(ret_val) == 0:
                    raise InvalidLegacyXMLFileError(
                        "missing {} section "
                        "for displacement number {}".format(tag, dispnum))
            return ret_val

        def _get_exactly_one(parent, tag, dispnum):
            ret_val = _get_at_least_one(parent, tag, dispnum)
            if sanity_checking_enabled:
                if len(ret_val) > 1:
                    raise InvalidLegacyXMLFileError(
                        "multiple {} sections "
                        "for displacement number {}".format(tag, dispnum))
            return ret_val[0]

        #========================================#
        etr = ElementTree.parse(file)
        for disp in etr.iter('displacement'):
            disp_number = disp.get('number', '<unnumbered>')
            # Get the molecule part
            mol_sect = _get_exactly_one(disp, 'molecule', disp_number)
            # Get the XYZ section
            xyz_sect = _get_exactly_one(mol_sect, 'xyz', disp_number)
            if 'units' in xyz_sect.keys():
                unitstr = xyz_sect.get('units')
                units = eval(unitstr.title(), globals())
            else:
                units = DistanceUnit.default
            energy_el = _get_at_least_one(disp, 'energy', disp_number)
            # for now just use the "molecular" energy
            energy_el = [
                e for e in energy_el if e.get('type', '') == 'molecular'
            ]
            if len(energy_el) == 0:
                raise InvalidLegacyXMLFileError(
                    "missing energy with type='molecular' "
                    "for displacement number {}".format(disp_number))
            elif len(energy_el) > 1:
                raise InvalidLegacyXMLFileError(
                    "multiple energy elements with type='molecular' "
                    "for displacement number {}".format(disp_number))
            energy_el = energy_el[0]
            if 'units' in energy_el.keys():
                unitstr = energy_el.get('units')
                energy_units = eval(unitstr.title(), globals())
            else:
                energy_units = Hartrees
            energy_val = float(energy_el.get('value')) * energy_units
            mol_stub = MoleculeStub(xyz_sect.text, units=units)
            energy = Energy(mol_stub,
                            units=energy_units,
                            details=ComputationDetails(type='molecular'))
            energy.value = energy_val
            self.properties[mol_stub].append(energy)
Ejemplo n.º 5
0
 def has_property_for_molecule(self, molecule, property, details=None, verbose=True):
     if molecule in self.properties:
         props = self.properties[molecule]
         for p in props:
             pcopy = copy(p)
             pcopy.molecule = molecule
             self.properties_for_molecules[molecule].append(pcopy)
             if MolecularProperty.is_same_property(property, p):
                 if ComputationDetails.is_compatible_details(details, p.details):
                     return True
     return False
Ejemplo n.º 6
0
 def has_property_for_molecule(self,
                               molecule,
                               property,
                               details=None,
                               verbose=True):
     if molecule in self.properties:
         props = self.properties[molecule]
         for p in props:
             pcopy = copy(p)
             pcopy.molecule = molecule
             self.properties_for_molecules[molecule].append(pcopy)
             if MolecularProperty.is_same_property(property, p):
                 if ComputationDetails.is_compatible_details(
                         details, p.details):
                     return True
     return False