A general approach is developed to search for stable structures of short chain fragments (e.g. of loops or bound oligopeptides) in a given molecular field. This molecular field is produced by the remaining part of a globule or by any other surface with a defined spatial structure. The fragment must be short enough to have no pronounced long-range interactions within itself. The method is illustrated by calculation of the 3-D structures of two loops of bovine pancreatic trypsin inhibitor (BPTI). Computations are based on a lattice model of conformational space and on strict and fast algorithms of 1-D statistical mechanics and dynamic programming (which are very similar in essence). This makes a search of oligopeptide structures only several times (and not several orders of magnitude) longer than that of a dipeptide.