A new approach is presented for determining the rigid regions in proteins and the flexible joints between them. The short-range forces in proteins are modeled as constraints and we use a recently developed formalism from graph theory to analyze flexibility in the bond network. Forces included in the analysis are the covalent bond-stretching and bond-bending forces, salt bridges, and hydrogen bonds. We use a local function to associate an energy with individual hydrogen bonds, which then can be included or excluded depending on the bond strength. Colored maps of the rigid and flexible regions provide a direct visualization of where the motion of the protein can take place, consistent with these distance constraints. We also define a flexibility index that quantifies the local density of flexible or floppy modes, in terms of the dihedral angles that remain free to rotate in each flexible region. A negative flexibility index provides a measure of the density of redundant bonds in rigid regions. A new application of this approach is to simulate the maximal range of possible motions of the flexible regions by introducing Monte Carlo changes in the free dihedral angles, subject to the distance constraints. This is done using a method that maintains closure of the rings formed by covalent and hydrogen bonds in the flexible parts of the protein, and van der Waals overlaps between atoms are avoided. We use the locus of the possible motions of HIV protease as an example: movies of its motion can be seen at http://www.pa.msu.edu/~lei.