3
$\begingroup$

This code:

Clear[ighamiltMol,timeList,hamiltMol,];

timeList={Abs[0.333333 E^(-I t) + 0.333333 E^(I t) + 0.166667 E^(-2 I t) + 
   0.166667 E^(2 I t)]^2, 
 Abs[0.\[VeryThinSpace]+ 0.166667 E^(-I t) - 0.166667 E^(I t) + 
   0.166667 E^(-2 I t) - 0.166667 E^(2 I t)]^2, 
 Abs[-0.166667 E^(-I t) - 0.166667 E^(I t) + 0.166667 E^(-2 I t) + 
   0.166667 E^(2 I t)]^2, 
 Abs[-0.333333 E^(-I t) + 0.333333 E^(I t) + 0.166667 E^(-2 I t) - 
   0.166667 E^(2 I t)]^2, 
 Abs[0.\[VeryThinSpace]- 0.166667 E^(-I t) - 0.166667 E^(I t) + 
   0.166667 E^(-2 I t) + 0.166667 E^(2 I t)]^2, 
 Abs[0.166667 E^(-I t) - 0.166667 E^(I t) + 0.166667 E^(-2 I t) - 
       0.166667 E^(2 I t)]^2}

hamiltMol={{0, 1, 0, 0, 0, 1}, {1, 0, 1, 0, 0, 0}, {0, 1, 0, 1, 0, 0}, {0, 0, 1,
   0, 1, 0}, {0, 0, 0, 1, 0, 1}, {1, 0, 0, 0, 1, 0}}

ighamiltMol = 
  Dynamic@AdjacencyGraph[hamiltMol, 
    VertexLabels -> Placed["Name", Tooltip], 
    GraphStyle -> "SpringEmbedding", 
    VertexShapeFunction -> (Disk[#1, timeList[[#2]]] &)];

Animator[Dynamic[t], {0, 19}, .5]
ighamiltMol

Generates this animation (2 pictures shown, notice the resizing): Mathematica graphics Mathematica graphics

I would like my disks' radii not to exceed 2/3 of the distance between two vertices, so that the graph needs no resizing.

The same method applied to GraphPlot[] and GraphPlot3D[] also does not work, producing results like those obtained with AdjacencyGraph[]. I've tried setting a DataRange->{}, but it doesn't work either. Rescale[]ing didn't work.

(Note that this is not a problem in a Graphics[] environment.)

I don't know what to try next.

$\endgroup$
4
  • 1
    $\begingroup$ Your pasted code is incomplete. E.g. in the first snippet, hamiltMoland timeCoeff are not defined. $\endgroup$
    – Yves Klett
    Commented Mar 16, 2012 at 7:34
  • $\begingroup$ They are - commented out. hamiltMol is an adjacency matrix and timeCoeff[] looks in a table containing complex exponentials, one per vertex. The problem occurs even with a square and a Sin[] varying disk radius. $\endgroup$
    – CHM
    Commented Mar 16, 2012 at 8:16
  • 2
    $\begingroup$ Working code will get you more takers. Just paste in a toy example, if the original is too complex. $\endgroup$
    – Yves Klett
    Commented Mar 16, 2012 at 8:44
  • 1
    $\begingroup$ @YvesKlett The code has been edited. $\endgroup$
    – CHM
    Commented Mar 16, 2012 at 20:15

1 Answer 1

4
$\begingroup$

Assuming that timecoeff is scaled between 0 and 1 you could do something like this (I just made something up for timecoeff and hamiltMol):

Clear[ighamiltMol, t]; t = 0;
timeCoeff[i_] := (1 + Sin[t + 2.5 i])/2
hamiltMol = NestList[RotateRight, {0, 1, 0, 0, 0, 1}, 5];

ighamiltMol = 
 Dynamic@AdjacencyGraph[hamiltMol,(*hamiltMol is a symmetric sparse/
   adjacency matrix*)
   EdgeShapeFunction -> (Line[#1] &),
   VertexLabels -> Placed["Name", Tooltip], 
   GraphStyle -> "SpringEmbedding", 
   VertexShapeFunction -> ({{Opacity[0], Disk[#1, #3]},
       Disk[#1, #3 timeCoeff[#2] ]} &),
   VertexSize -> 
    4/3];(*timeCoeff[] looks in a list of complex \
exponentials*)Animator[Dynamic[t], {0, 2 Pi}, .1]
ighamiltMol

Mathematica graphics

This works by using a VertexShapeFunction which consists of two disks on top of each other, namely a transparent one with a fixed radius, and a solid one with a varying radius. The option VertexSize -> 4/3 makes sure that the maximum radius is equal to 2/3 time the mimimum length of all vertices.

$\endgroup$
4
  • $\begingroup$ Changing VertexSize doesn't work for me, neither does adding a normalization factor to timeCoeff[]. I think the problem lies in the space that's allocated for the graph by Mathematica - it's constantly updated. What I'd like is for the graph to be centered in a wider canvas, so there's no need to resize. $\endgroup$
    – CHM
    Commented Mar 16, 2012 at 20:33
  • 1
    $\begingroup$ The invisible disks should prevent the size of the graph from changing as t changes. VertexSize only works in combination with multiplying the radius of the disks with the third argument supplied to VertexShapeFunction. $\endgroup$
    – Heike
    Commented Mar 16, 2012 at 20:43
  • $\begingroup$ Turns out EdgeShapeFunction was essential. Thank you =) $\endgroup$
    – CHM
    Commented Mar 16, 2012 at 20:59
  • 1
    $\begingroup$ Heike, congratulations on the first tag badge! $\endgroup$
    – Mr.Wizard
    Commented Mar 18, 2012 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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