We associate with each graph
(
S
,
E
)
(S,E)
a
2
2
-step simply connected nilpotent Lie group
N
N
and a lattice
Γ
\Gamma
in
N
N
. We determine the group of Lie automorphisms of
N
N
and apply the result to describe a necessary and sufficient condition, in terms of the graph, for the compact nilmanifold
N
/
Γ
N/\Gamma
to admit an Anosov automorphism. Using the criterion we obtain new examples of compact nilmanifolds admitting Anosov automorphisms, and conclude that for every
n
≥
17
n\geq 17
there exist a
n
n
-dimensional
2
2
-step simply connected nilpotent Lie group
N
N
which is indecomposable (not a direct product of lower dimensional nilpotent Lie groups), and a lattice
Γ
\Gamma
in
N
N
such that
N
/
Γ
N/\Gamma
admits an Anosov automorphism; we give also a lower bound on the number of mutually nonisomorphic Lie groups
N
N
of a given dimension, satisfying the condition. Necessary and sufficient conditions are also described for a compact nilmanifold as above to admit ergodic automorphisms.