0

I have the following code to annotate a graph using property maps:

from graph_tool.all import *

# define graph
g = Graph()
g.set_directed(True)
species = g.new_vertex_property("string")
species_dict = {}
reaction_dict = {}

#add species and reactions
s1 = g.add_vertex()
species[s1] = 'limonene'
species_dict[g.vertex_index[s1]] = 'limonene'

g.vertex_properties["species"] = species
g.vp.species[s1]

When I run this I obtain the following error message:

File "/home/pmj27/projects/NOC/exergy/make_graph.py", line 45, in <module>
g.vp.species[s1]

AttributeError: 'PropertyDict' object has no attribute 'species'

Why is this? If I type g.vp into my IPython console I get {'species': <PropertyMap object with key type 'Vertex' and value type 'string', for Graph 0x7f285d90ea10, at 0x7f285d90ef90>} as answer, so there clearly is a property map.

P-M
  • 1,279
  • 2
  • 21
  • 35

1 Answers1

1

The access to property maps via attributes (as g.vp.species[s1] in your example) is only available in more recent versions of graph-tool (currently 2.11, as of Nov 2015). In the version you are using (2.2.42), you must use the dictionary interface: g.vp["species"][s1].

Tiago Peixoto
  • 5,149
  • 2
  • 28
  • 28