#include "pdb.h" void set_atom_selection_on (atom_record *atom, int what,int index) { atom->flags |= what ; } void set_atom_selection_off(atom_record *atom, int what,int index) { atom->flags &= what ; } /* set the selction bit of all atoms to be on with the given bits */ void turn_selection_on(file_records *file, int what) { traverse_file_atom_records(file,set_atom_selection_on,what); } void turn_selection_off(file_records *file, int what) { traverse_file_atom_records(file,set_atom_selection_off, ~what); } void setup_flags_from_file(file_records* file, FILE *ff, int flag,int do_and) { char string [200] ; char chain ; int resnum ; while(fgets(string,200,ff) != NULL) { int ii = 0 ; int x_char = ' ' ; while(string[ii] != 0 ) { string[ii] = toupper(string[ii]) ; ii++; } if (string[ii-1] == '\n') string[ii -1] = '\0' ; ii = 0 ; while(isspace(string[ii])|| string[ii] == '_' ) ii++; if(isdigit(string[ii])) { resnum =atoi(string+ii); while (isdigit(string[ii])) ii++; if (string[ii]) chain= string[ii++] ; else chain = ' '; if (chain == '_') chain = ' ' ; } else { chain = string[ii++]; resnum =atoi(string+ii); while (isdigit(string[ii])) ii++; if (string[ii] && string[ii] != '\n' && string[ii] != '_') x_char = string[ii++] ; } { residue_record * res = residue_by_number(file,resnum,chain,x_char); if(res == NULL) serious_error(ARG_TYPE_STRING, "Failed to find residue for selection", string); while (isspace(string[ii])|| string[ii] == '_') ii++; if(string[ii]) { while(string[ii]) { int here = ii ; while(!isspace(string[ii]) && string[ii] && string[ii] != '_') ii++; if (string[ii]) string[ii++] = 0 ; { atom_record *atom = find_atom_in_residue(res,string +here); if(atom == NULL) serious_error(ARG_TYPE_STRING, "Failed to find atom in residue for selection", string); atom->flags = do_and ? atom->flags & flag : atom->flags | flag; } while(isspace(string[ii]) || string[ii] == '_') ii++; } } else traverse_residue_atoms(res,do_and ? set_atom_selection_off : set_atom_selection_on, flag) ; } } } void select_residues_for_calculation (file_records *file, char *what,int fromfile) { FILE *ff ; atom_record *atom ; int number ; if (!fromfile) { char * poi = what ; while( *poi) { if (*poi == '|') *poi = '\n' ; poi++; } ff = stream_from_string (what) ; } else { ff = fopen(what,"r"); if (ff == NULL) serious_error (1,"Failed to open residue file",what); } turn_selection_on(file, DONT_CALCULATE_ATOM) ; setup_flags_from_file(file,ff, ~DONT_CALCULATE_ATOM, 1); fclose(ff) ; } void select_atoms_for_calculation (file_records *file, char *what) { int from_string = isdigit(what[0]) ; FILE *ff ; atom_record *atom ; int number ; if (from_string) { ff = stream_from_string (what) ; } else { ff = fopen(what,"r"); if (ff == NULL) serious_error (1,"Failed to open selection file",what); } turn_selection_on(file, DONT_CALCULATE_ATOM) ; while (fscanf(ff,"%d",&number) > 0) { atom = atom_by_number (file, number) ; if (atom == NULL) warning(2,"Failed to find atom for selection", number) ; else SWITCH_OFF(atom , DONT_CALCULATE_ATOM) ; } fclose (ff) ; } char * selection_argument = NULL ; char * residue_selection_argument = NULL; char * residue_selection_file = NULL ; void setup_selection (file_records *file) { if(selection_argument != NULL) select_atoms_for_calculation (file, selection_argument); if (residue_selection_argument != NULL) select_residues_for_calculation (file, residue_selection_argument,0); if (residue_selection_file != NULL) select_residues_for_calculation (file, residue_selection_file,1); } void select_protein_atoms(file_records *file) { turn_selection_on(file, DONT_CALCULATE_ATOM) ; traverse_file_protein_atoms(file,set_atom_selection_off, ~ DONT_CALCULATE_ATOM) ; } void ignore_water_atoms(file_records *file) { traverse_file_water_atoms(file,set_atom_selection_on, IGNORE_ATOM) ; } void ignore_hetatm(atom_record *atom, void *ignore , int index) { if (atom->atomtype != RECORD_ATOM) SWITCH_ON(atom, IGNORE_ATOM) ; } void ignore_hetatms(file_records *file) { traverse_file_atom_records(file, ignore_hetatm, NULL); }