Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

One thing I use Mathematica for is building molecular graphs.

Until now, I've been content with generating an adjacency matrix from SMILES data, and passing that to AdjacencyGraph. That works well for small cyclic graphs, but the method fails my expectations when the molecules are polycyclic. I want all the edges to be of unit length, but none of the GraphLayout option values permit that.

Undesired layout

GraphEdit

The GraphUtilities package contains an interactive graphing function. It enables one to draw any graph, and outputs the relevant data to reconstructing it.

It would be of great help if I could pre-define graphs for GraphEdit to use, that could be copied any number of times inside the applet, while retaining their shapes. This screenshot (from ChemDraw) illustrates what I'm looking for:

enter image description here

Also, directly passing a Graph object to GraphEdit doesn't work:

GraphEdit[CycleGraph[6]]

(* GraphEdit[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 4, 
    4 \[UndirectedEdge] 5, 5 \[UndirectedEdge] 6, 6 \[UndirectedEdge] 1}] *)

Can I add such functionality to GraphEdit?

share|improve this question
    
Actually enhancing the applet might be very much overkill. I'm a bit confused that, while Head@CycleGraph is Graph, GraphEdit doesn't accept it. –  CHM Aug 13 '12 at 4:22
    
Could you please put back part of the code that you had originally? Then my answer will make more sense for others. I will also be able to add more details in my answer. –  Vitaliy Kaurov Aug 13 '12 at 4:40
    
I think it would be quite an elaborate task to modify GraphEdit. I updated my answer. –  Vitaliy Kaurov Aug 13 '12 at 5:35
add comment

1 Answer

This question may give you a good general direction:

Generating graphs interactively (GUI)

Part 1: GraphEdit

Use Rule to pass graphs to GraphEdit:

gr = Rule @@@ Partition[Range[6], 2, 1, 1]

{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 1}

Needs["GraphUtilities`"]
GraphEdit[gr]

enter image description here

AdjacencyGraph is a new graph functionality added in version 8. It has the whole new data format that older GraphEdit function cannot understand. You have to use Rule to pass a graph to GraphEdit, instead of UndirectedEdge or other objects associated with or produced by Graph, such as CycleGraph.

Part 2: programmatic drawing

You can code perfect linked polygons in this way:

h[x_, y_] := Polygon[Table[{Cos[2 Pi k/6] + x, Sin[2 Pi k/6] + y}, {k, 6}]]

Graphics[{EdgeForm[Opacity[.7]], LightBlue, 
  Table[h[3 i + 3 ((-1)^j + 1)/4, Sqrt[3]/2 j], {i, 5}, {j, 2}]}]

enter image description here

Part 3: interactive drawing and copying

If your ultimate goal is draw, copy and move polygonal objects, then maybe Drawing Tools palette can help? Have you seen this video ?

enter image description here

share|improve this answer
    
The question you linked to is mine ;) Indeed, Heike's answer is very nice, and I do use it in my notebooks. I was wondering if adding a button or two to GraphEdit was at all possible, since it might be a more general, less ad-hoc, way of solving the problem. Thanks for the tips. –  CHM Aug 13 '12 at 6:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.