You specify the theme you are looking for, and the database to look for them, in CQL. Then you run this CQL file using cql.exe . This creates a new PGN file that has all the games matching your theme.
CQL specifies a small but powerful set of primitives to define chess themes. CQL can find much more complex themes than any other chess program. Users have searched for themes like stalemates with multiple pins; games in which the same position recurs but with the winning side missing just one piece; Nowotny and Grimshaw themes, games with some number of captures on a single square, games with a certain number of black and white passed pawns, and many more.
Questions or comments about CQL should be directed to firstname.lastname@example.org . Feel free to ask for code to build themes you are interested in.
Two references for good introductions to CQL are:
CQL was developed by Gady Costeff and Lewis Stiller. It is Copyright (c) 2003-2004 and is free. It also uses Scid code by Shane Hudson. The Windows build uses the Cygwin Libraries.