Esempio n. 1
0
    def test_load_metal_library(self):
        """Test we can obtain metal parameters from a library"""

        test_entry = Entry(
            index=1,
            label="Pt111",
            binding_energies={
                'H': Energy(-2.75367887E+00, 'eV/molecule'),
                'C': Energy(-7.02515507E+00, 'eV/molecule'),
                'N': Energy(-4.63224568E+00, 'eV/molecule'),
                'O': Energy(-3.81153179E+00, 'eV/molecule'),
            },
            surface_site_density=SurfaceConcentration(2.483E-09, 'mol/cm^2'),
            facet="111",
            metal="Pt",
            short_desc=u"fcc",
            long_desc=u"""
        Calculated by Katrin Blondal and Bjarne Kreitz at Brown University
            """,
        )

        self.assertEqual(
            repr(self.database.get_binding_energies(test_entry.label)),
            repr(test_entry.binding_energies))
        self.assertEqual(
            repr(self.database.get_surface_site_density(test_entry.label)),
            repr(test_entry.surface_site_density))
Esempio n. 2
0
    def __init__(
        self,
        groundStateDegeneracy=-1,
        numberOfAtoms=None,
        stericEnergy=None,
        molecularMass=None,
        energy=0,
        atomicNumbers=None,
        rotationalConstants=None,
        atomCoords=None,
        frequencies=None,
        source=None,
    ):
        #: Electronic ground state degeneracy in RMG taken as number of radicals +1
        self.groundStateDegeneracy = groundStateDegeneracy
        self.numberOfAtoms = numberOfAtoms  #: Number of atoms.
        self.stericEnergy = Energy(stericEnergy)
        self.molecularMass = Mass(molecularMass)
        self.energy = Energy(energy)
        self.atomicNumbers = atomicNumbers
        self.rotationalConstants = Frequency(rotationalConstants)
        self.atomCoords = Length(atomCoords)
        self.frequencies = Frequency(frequencies)
        self.source = source

        self.testValid()
Esempio n. 3
0
 def testJoback(self):
     #values calculate from joback's estimations
     self.testCases = [
         [
             'acetone', 'CC(=O)C',
             Length(5.36421, 'angstroms'),
             Energy(3.20446, 'kJ/mol'),
             "Epsilon & sigma estimated with Tc=500.53 K, Pc=47.11 bar (from Joback method)"
         ],
         [
             'cyclopenta-1,2-diene', 'C1=C=CCC1', None, None, None
         ],  # not sure what to expect, we just want to make sure it doesn't crash
         ['benzene', 'c1ccccc1', None, None, None],
     ]
     for name, smiles, sigma, epsilon, comment in self.testCases:
         species = Species(molecule=[Molecule(SMILES=smiles)])
         transportData, blank, blank2 = self.transportdb.getTransportPropertiesViaGroupEstimates(
             species)
         # check Joback worked.
         # If we don't know what to expect, don't check (just make sure we didn't crash)
         if comment:
             self.assertTrue(transportData.comment == comment)
         if sigma:
             self.assertAlmostEqual(transportData.sigma.value_si * 1e10,
                                    sigma.value_si * 1e10, 4)
         if epsilon:
             self.assertAlmostEqual(transportData.epsilon.value_si,
                                    epsilon.value_si, 1)
Esempio n. 4
0
    def test_joback(self):
        """Test transport property estimation via Joback groups."""
        self.testCases = [
            [
                'acetone', 'CC(=O)C',
                Length(5.36421, 'angstroms'),
                Energy(3.20446, 'kJ/mol'),
                "Epsilon & sigma estimated with Tc=500.53 K, Pc=47.11 bar (from Joback method)"
            ],
            [
                'cyclopenta-1,2-diene', 'C1=C=CCC1', None, None, None
            ],  # not sure what to expect, we just want to make sure it doesn't crash
            ['benzene', 'c1ccccc1', None, None, None],
        ]

        # values calculate from joback's estimations
        for name, smiles, sigma, epsilon, comment in self.testCases:
            species = Species().from_smiles(smiles)
            transport_data, blank, blank2 = self.database.get_transport_properties_via_group_estimates(
                species)
            # check Joback worked.
            # If we don't know what to expect, don't check (just make sure we didn't crash)
            if comment:
                self.assertTrue(transport_data.comment == comment)
            if sigma:
                self.assertAlmostEqual(transport_data.sigma.value_si * 1e10,
                                       sigma.value_si * 1e10, 4)
            if epsilon:
                self.assertAlmostEqual(transport_data.epsilon.value_si,
                                       epsilon.value_si, 1)
Esempio n. 5
0
def convertBindingEnergies(bindingEnergies):
    """
    Process the bindingEnergies from the input file.
    If "None" is passed, then it returns Pt(111) values.

    :param bindingEnergies: a dictionary of element symbol: binding energy pairs (or None)
    :return: the processed and checked dictionary
    """
    if bindingEnergies is None:
        bindingEnergies = { # default values for Pt(111)
                       'C':(-6.750, 'eV/molecule'),
                       'H':(-2.479, 'eV/molecule'),
                       'O':(-3.586, 'eV/molecule'),
                       'N':(-4.352, 'eV/molecule'),
                       }
        logging.info("Using default binding energies for Pt(111):\n{0!r}".format(bindingEnergies))
    if not isinstance(bindingEnergies, dict): raise InputError("bindingEnergies should be None (for default) or a dict.")
    newDict = {}
    for element in 'CHON':
        try:
            newDict[element] = Energy(bindingEnergies[element])
        except KeyError:
            logging.error('Element {} missing from bindingEnergies dictionary'.format(element))
            raise
    return newDict
Esempio n. 6
0
    def test_write_entry_to_database(self):
        """Test we can write an entry to the database"""

        test_entry = Entry(
            index=100,
            label="Me111",
            binding_energies={
                'H': Energy(0., 'eV/molecule'),
                'C': Energy(0., 'eV/molecule'),
                'N': Energy(0., 'eV/molecule'),
                'O': Energy(0., 'eV/molecule'),
            },
            surface_site_density=SurfaceConcentration(0., 'mol/cm^2'),
            facet="111",
            metal="Me",
            short_desc=u"fcc",
            long_desc=u"""
        Test
            """,
        )

        MetalLib = self.database.libraries['surface']
        self.database.add_entry(test_entry)

        # test to see if the entry was added
        self.assertEqual(
            repr(self.database.get_binding_energies(test_entry.label)),
            repr(test_entry.binding_energies))
        self.assertEqual(
            repr(self.database.get_surface_site_density(test_entry.label)),
            repr(test_entry.surface_site_density))

        # write the new entry
        self.database.save(
            os.path.join(settings['database.directory'], 'surface'))
        # MetalLib.save_entry(os.path.join(settings['database.directory'], 'surface/libraries/metal.py'), test_entry)

        # test to see if entry was written
        with open(
                os.path.join(settings['database.directory'],
                             'surface/libraries/metal.py'), "r") as f:
            if "Me111" in f.read():
                self.database.remove_entry(test_entry)
                self.database.save(
                    os.path.join(settings['database.directory'], 'surface'))
            else:
                raise DatabaseError("Unable to write entry to database.")
Esempio n. 7
0
 def __init__(self, shapeIndex=None, epsilon=None, sigma=None, dipoleMoment=None, polarizability=None,
              rotrelaxcollnum=None, comment=''):
     self.shapeIndex = shapeIndex
     try:
         self.epsilon = Energy(epsilon)
     except quantity.QuantityError:
         self.epsilon = quantity.Temperature(epsilon)
         self.epsilon.value_si *= constants.R
         self.epsilon.units = 'kJ/mol'
     self.sigma = Length(sigma)
     self.dipoleMoment = DipoleMoment(dipoleMoment)
     self.polarizability = Volume(polarizability)
     self.rotrelaxcollnum = rotrelaxcollnum
     self.comment = comment
Esempio n. 8
0
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        self.shapeIndex = 1
        self.epsilon = Energy(2.104, 'kJ/mol')
        self.sigma = Length(3.402, 'angstroms')
        self.dipoleMoment = DipoleMoment(1.000, 'C*m')
        self.polarizability = Volume(0.134, 'angstroms^3')
        self.rotrelaxcollnum = 0.000
        self.comment = 'test'

        self.transport = TransportData(
            shapeIndex=self.shapeIndex,
            epsilon=self.epsilon,
            sigma=self.sigma,
            dipoleMoment=self.dipoleMoment,
            polarizability=self.polarizability,
            rotrelaxcollnum=self.rotrelaxcollnum,
            comment=self.comment,
        )
Esempio n. 9
0
        else:
            productsToRemove.append(product)
    for product in productsToRemove:
        network.products.remove(product)

################################################################################

if __name__ == '__main__':
    
    # Parse the command-line arguments
    args = parseCommandLineArguments()
    
    if args.max_energy:
        Emax = float(args.max_energy[0])
        Eunits = str(args.max_energy[1])
        Emax = Energy(Emax, Eunits).value_si
    else:
        Emax = None
    
    # Load RMG dictionary if specified
    moleculeDict = {}
    if args.dictionary is not None:
        f = open(args.dictionary[0])
        adjlist = ''; label = ''
        for line in f:
            if len(line.strip()) == 0:
                if len(adjlist.strip()) > 0:
                    molecule = Molecule()
                    molecule.fromAdjacencyList(adjlist)
                    moleculeDict[label] = molecule
                adjlist = ''; label = ''