def testStoreAndRetrieve(self):
        reinitdb()
        graph = Graph.Graph()
        coords = Infoset.Infoset(graph, InfosetType.getCoordsType())
        labels = Infoset.Infoset(graph, InfosetType.getAtomLabelType())
        bondtypes = Infoset.Infoset(graph, InfosetType.getBondTypeType())
        energy = Infoset.Infoset(graph, InfosetType.getHFEnergyType())
        angles = Infoset.Infoset(graph, InfosetType.getAngleType())

        node1 = graph.createEntity()
        node2 = graph.createEntity()
        node3 = graph.createEntity()
        link = graph.createEntity((node1, node2))
        angle = graph.createEntity((node1, node2, node3))

        coords.setValue(node1, (10.0, 0.0, 0.0))
        coords.setValue(node2, (10.0, 2.0, 0.0))
        coords.setValue(node3, (10.0, 2.0, 3.0))

        bondtypes.setValue(link, 2)
        angles.setValue(angle, Measure.Measure(45, Units.degrees))

        db = DBAccess.DBAccess(os.path.join(moduleDir(), "testdb"))
        db.store(graph)

        molecule_list = db.retrieveAll()
        self.assertEqual(len(molecule_list), 1)
    def testSearch(self):
        reinitdb()
        db = DBAccess.DBAccess(os.path.join(moduleDir(), "testdb"))

        for i in xrange(1, 90):
            graph = Graph.Graph()
            coords = Infoset.Infoset(graph, InfosetType.getCoordsType())
            labels = Infoset.Infoset(graph, InfosetType.getAtomLabelType())
            bondtypes = Infoset.Infoset(graph, InfosetType.getBondTypeType())
            energy = Infoset.Infoset(graph, InfosetType.getHFEnergyType())
            angles = Infoset.Infoset(graph, InfosetType.getAngleType())

            node1 = graph.createEntity()
            node2 = graph.createEntity()
            node3 = graph.createEntity()
            link = graph.createEntity((node1, node2))
            angle = graph.createEntity((node1, node2, node3))

            coords.setValue(node1, (10.0, 0.0, 0.0))
            coords.setValue(node2, (10.0, 2.0, 0.0))
            coords.setValue(node3, (10.0, 2.0, 3.0))

            bondtypes.setValue(link, 2)

            angles.setValue(angle, Measure.Measure(float(i), Units.degrees))
            db.store(graph)
Exemple #3
0
    def testEntityDeletionCascade(self):  # fold>>
        graph = Graph.Graph()
        coords = Infoset.Infoset(graph, InfosetType.getCoordsType())
        labels = Infoset.Infoset(graph, InfosetType.getAtomLabelType())
        bondtypes = Infoset.Infoset(graph, InfosetType.getBondTypeType())
        angles = Infoset.Infoset(graph, InfosetType.getAngleType())

        node1 = graph.createEntity()
        node2 = graph.createEntity()
        node3 = graph.createEntity()
        link = graph.createEntity((node1, node2))
        angle_entity = graph.createEntity((node1, node2, node3))

        coords.setValue(node1, (10.0, 0.0, 0.0))
        coords.setValue(node2, (10.0, 2.0, 0.0))
        coords.setValue(node3, (10.0, 2.0, 3.0))

        bondtypes.setValue(link, 2)
        angles.setValue(angle_entity, 45.0)

        graph.deleteEntity(node1)

        self.assertEqual(coords.size(), 2)
        self.assertEqual(labels.size(), 2)
        self.assertEqual(bondtypes.size(), 0)
        self.assertEqual(angles.size(), 0)
Exemple #4
0
    def testGetInfoset(self):  # fold>>
        graph = Graph.Graph()
        coords = Infoset.Infoset(graph, InfosetType.getCoordsType())
        coords2 = Infoset.Infoset(graph, InfosetType.getCoordsType())
        labels = Infoset.Infoset(graph, InfosetType.getAtomLabelType())
        bondtypes = Infoset.Infoset(graph, InfosetType.getBondTypeType())
        angles = Infoset.Infoset(graph, InfosetType.getAngleType())
        energy = Infoset.Infoset(graph, InfosetType.getHFEnergyType())

        self.assertEqual(len(graph.getInfosets()), 6)

        self.assertEqual(len(graph.getInfosets(dimensionality=0)), 1)
        self.assertEqual(len(graph.getInfosets(dimensionality=1)), 3)
        self.assertEqual(len(graph.getInfosets(dimensionality=2)), 1)
        self.assertEqual(len(graph.getInfosets(dimensionality=3)), 1)
        self.assertEqual(len(graph.getInfosets(dimensionality=4)), 0)

        self.assertEqual(len(graph.getInfosets(uuid=coords.uuid())), 1)
        self.assertEqual(len(graph.getInfosets(uuid=labels.uuid())), 1)
        self.assertEqual(len(graph.getInfosets(uuid=uuid.uuid4())), 0)

        self.assertEqual(
            len(graph.getInfosets(infoset_type=InfosetType.getCoordsType())),
            2)
        self.assertEqual(
            len(graph.getInfosets(infoset_type=InfosetType.getHFEnergyType())),
            1)
        self.assertEqual(len(graph.getInfosets(infoset_type=list)), 0)

        self.assertEqual(
            len(graph.getInfosets(uuid=labels.uuid(), dimensionality=1)), 1)
        self.assertEqual(
            len(graph.getInfosets(uuid=labels.uuid(), dimensionality=2)), 0)
    def __init__(self, atom_list): # fold>>
        self._graph = Graph.Graph()
        self._elements = Infoset.Infoset(self._graph, InfosetType.getElementType())
        self._labels = Infoset.Infoset(self._graph, InfosetType.getAtomLabelType())
        self._coords = Infoset.Infoset(self._graph, InfosetType.getCoordsType())

        for atom in atom_list:
            entity = self._graph.createEntity()
            self._elements.setValue(entity, atom[0])
            self._coords.setValue(entity, atom[1])
    def testSearch(self):
        reinitdb()
        db = DBAccess.DBAccess(os.path.join(moduleDir(), "testdb"))

        for i in xrange(1, 90):
            graph = Graph.Graph()
            coords = Infoset.Infoset(graph, InfosetType.getCoordsType())
            labels = Infoset.Infoset(graph, InfosetType.getAtomLabelType())
            bondtypes = Infoset.Infoset(graph, InfosetType.getBondTypeType())
            energy = Infoset.Infoset(graph, InfosetType.getHFEnergyType())
            angles = Infoset.Infoset(graph, InfosetType.getAngleType())

            node1 = graph.createEntity()
            node2 = graph.createEntity()
            node3 = graph.createEntity()
            link = graph.createEntity((node1, node2))
            angle = graph.createEntity((node1, node2, node3))

            coords.setValue(node1, (10.0, 0.0, 0.0))
            coords.setValue(node2, (10.0, 2.0, 0.0))
            coords.setValue(node3, (10.0, 2.0, 3.0))

            bondtypes.setValue(link, 2)

            angles.setValue(angle, Measure.Measure(float(i), Units.degrees))
            db.store(graph)

        class Search:
            def __init__(self, angle):
                self._angle = angle

            def satisfiedBy(self, graph):
                infoset = graph.getInfosets(
                    infoset_type=InfosetType.getAngleType())[0]
                if infoset is None:
                    return False
                #if infoset.value(angle).value() > 45.0 and infoset.value(angle).value() < 48.0:
                #    return True
                if infoset.value(angle).value() % 2 == 0:
                    return True

                return False

        results = db.search(Search(angle))
        #self.assertEqual(len(results), 2)
        for i in results:
            print i.getInfosets(
                infoset_type=InfosetType.getAngleType())[0].value(angle)
Exemple #7
0
    def testInfoset2(self):  # fold>>
        graph = Graph.Graph()
        coords = Infoset.Infoset(graph, InfosetType.getCoordsType())
        labels = Infoset.Infoset(graph, InfosetType.getAtomLabelType())
        bondtypes = Infoset.Infoset(graph, InfosetType.getBondTypeType())
        angles = Infoset.Infoset(graph, InfosetType.getAngleType())

        node1 = graph.createEntity()
        node2 = graph.createEntity()
        node3 = graph.createEntity()
        link = graph.createEntity((node1, node2))
        angle_entity = graph.createEntity((node1, node2, node3))

        coords.setValue(node1, (10.0, 0.0, 0.0))
        coords.setValue(node2, (10.0, 2.0, 0.0))

        self.assertEqual(coords.hasNone(), True)

        coords.setValue(node3, (10.0, 2.0, 3.0))

        self.assertEqual(coords.hasNone(), False)

        self.assertEqual(coords.value(node1), (10.0, 0.0, 0.0))
        self.assertEqual(coords.value(node2), (10.0, 2.0, 0.0))
        self.assertEqual(coords.value(node3), (10.0, 2.0, 3.0))

        bondtypes.setValue(link, 2)
        self.assertEqual(bondtypes.value(link), 2)
        self.assertEqual(bondtypes.hasNone(), False)

        angles.setValue(angle_entity, Measure.Measure(45.0, Units.degrees))
        self.assertEqual(angles.hasNone(), False)
        self.assertEqual(
            angles.value(angle_entity).value(),
            Measure.Measure(45.0, Units.degrees).value())

        graph.deleteEntity(node1)

        self.assertEqual(coords.size(), 2)
        self.assertEqual(labels.size(), 2)
        self.assertEqual(bondtypes.size(), 0)
        self.assertEqual(angles.size(), 0)