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)
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)
def __init__(self, atom_list): # fold>> self._graph = Graph.Graph() self._elements = Infoset.Infoset(self._graph, InfosetType.getElementType()) 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 testFromGraph(self): g = Graph.Graph() elements = Infoset.Infoset(g, InfosetType.getElementType()) coords = Infoset.Infoset(g, InfosetType.getCoordsType()) e = g.createEntity() elements.setValue(e, PeriodicTable.C) coords.setValue(e,Measure.Measure( ( 0.0000000000,8.5886187987,0.1625164475 ), Units.bohr)) e = g.createEntity() elements.setValue(e, PeriodicTable.C) coords.setValue(e,Measure.Measure( ( 0.0000000000,8.5886187987,0.1625164475 ), Units.bohr)) mol = XYZMolecule.fromGraph(g) self.assertEqual(mol.__class__, XYZMolecule.XYZMolecule)
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)
def testGraphInfoset(self): # fold>> graph = Graph.Graph() energy = Infoset.Infoset(graph, InfosetType.getHFEnergyType()) energy.setValue(None, Measure.Measure(10.4, Units.hartree)) self.assertEqual(energy.dimensionality(), 0) self.assertEqual(energy.size(), 1) self.assertEqual(energy.value(None).value(), 10.4) self.assertEqual(energy.value(None).unit(), Units.hartree)
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)
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 testInfoset(self): # fold>> graph = Graph.Graph() node1 = graph.createEntity() node2 = graph.createEntity() node3 = graph.createEntity() coords = Infoset.Infoset(graph, InfosetType.getCoordsType()) self.assertTrue(isinstance(coords, Infoset.Infoset)) self.assertEqual(coords.graph(), graph) self.assertNotEqual(coords.uuid(), None) self.assertEqual(coords.typeURI(), InfosetType.getCoordsType().typeURI()) self.assertEqual(coords.dimensionality(), InfosetType.getCoordsType().dimensionality()) self.assertEqual(coords.size(), 3) self.assertEqual(coords.hasNone(), True)
def testReification(self): # fold>> graph = Graph.Graph() node1 = graph.createEntity() node2 = graph.createEntity() node3 = graph.createEntity() coords = Infoset.Infoset(graph, InfosetType.getCoordsType()) self.assertEqual(len(coords.getReifications()), 0) id = coords.reify(ReificationTypeURI.COMMENT_REIFICATION_TYPE_URI, "hello") type_uri, value = coords.getReifications(id=id) self.assertEqual(type_uri, ReificationTypeURI.COMMENT_REIFICATION_TYPE_URI) self.assertEqual(value, "hello") self.assertEqual(len(coords.getReifications()), 1)