If you use "End Item" to track top level assemblies , you can query the DB as Kaushik said.
if not , you have to query all WTPartsMasters, where the oid (ida2a2) does not exist is the WTPartUsageLink table (ida3b5). ie WTpart that are not used as child in a BOM.
You can do that query by API