set mol [mol new propene.xyz waitfor all] animate delete all mol addfile propene.dcd waitfor all mol bondsrecalc $mol #pbc box -center origin # part one # select all molecules containing hydrogen set sel [atomselect $mol {same fragment as name "H.+"}] # get a list of atoms set fragdata [$sel get {index fragment name}] # now sort list of lists by fragment id to # have atoms in the same fragment lumped together. set fragdata [lsort -integer -index 1 $fragdata] # add terminal dummy atom. lappend fragdata {-1 -2 dummy} set oldfrag -1 set idxlist {} set tmplist {} # loop over atoms foreach atom $fragdata { foreach {idx frag name} $atom {} # new fragment? if {$oldfrag != $frag} { # this will write out all 4 atom molecules containing hydrogens # XXX: this part of the loop will need to be adjusted to whatever # logic is needed to determine the atoms if {[llength $tmplist] == 4} { puts stderr "found 4-atom fragment $oldfrag with atoms $tmplist" set idxlist [concat $idxlist $tmplist] } else { if {$oldfrag >= 0} { puts stderr "ignoring fragment $oldfrag with atoms $tmplist" } } set tmplist {} set oldfrag $frag } lappend tmplist $idx } # we are done with this selection $sel delete # part two # select all molecules containing carbon set sel [atomselect $mol {same fragment as name "C.+"}] # get a list of atoms set fragdata [$sel get {index fragment name}] # now sort list of lists by fragment id to # have atoms in the same fragment lumped together. set fragdata [lsort -integer -index 1 $fragdata] # add terminal dummy atom. lappend fragdata {-1 -2 dummy} set oldfrag -1 set tmplist {} # loop over atoms foreach atom $fragdata { foreach {idx frag name} $atom {} # new fragment? if {$oldfrag != $frag} { # this will write out all c atom molecules containing carbons # XXX: this part of the loop will need to be adjusted to whatever # logic is needed to determine the atoms if {[llength $tmplist] == 3} { puts stderr "found 3-atom fragment $oldfrag with atoms $tmplist" set idxlist [concat $idxlist $tmplist] } else { if {$oldfrag >= 0} { puts stderr "ignoring fragment $oldfrag with atoms $tmplist" } } set tmplist {} set oldfrag $frag } lappend tmplist $idx } # write out as pdb set newsel [atomselect $mol "index $idxlist"] $newsel writepdb selectedatoms.pdb $sel delete $newsel delete mol delete $mol