// ---------------------------------------------------------------------- void LocalizationMinMaxModule:: work( void ) throw() { if ( owner().is_anchor() ) state_ = minmax_finished; if ( state_ == minmax_finished ) return; if ( state_ == minmax_wait ) state_ = minmax_work; shawn::Vec est_pos; NeighborInfoList neighbors; collect_neighbors( neighborhood(), lat_anchors, neighbors ); if ( est_pos_min_max( neighbors, est_pos ) ) { if ( !observer().check_residue() || check_residue( neighbors, est_pos, lat_anchors, observer().comm_range() ) ) node_w().set_est_position( est_pos ); } state_ = minmax_finished; }
void genocide(int flags) { struct linked_list *ip; struct thing *mp; struct linked_list *nip; int which_monst; int blessed = flags & ISBLESSED; int cursed = flags & ISCURSED; while ((which_monst = get_monster_number("genocide")) == 0) ; if (cursed) /* oops... */ { new_level(THRONE, which_monst); msg("What's this I hear about you trying to wipe me out?"); fighting = running = after = FALSE; return; } /* Remove this monster from the present level */ for (ip = mlist; ip; ip = nip) { mp = THINGPTR(ip); nip = next(ip); if (mp->t_index == which_monst) { check_residue(mp); /* Check for special features before removing */ remove_monster(&mp->t_pos, ip); } } /* Remove from available monsters */ monsters[which_monst].m_normal = FALSE; monsters[which_monst].m_wander = FALSE; mpos = 0; msg("You have wiped out the %s.", monsters[which_monst].m_name); if (blessed) genocide(ISNORMAL); }
float ProteinEntropy::calculate(Soup * A, Soup * B) { vector<ProteinChain*> pcs = A->getProteinChains(); vector<Residue*> res; vector<Atom*> ligand_atoms = B->get_dry_atoms(); float entropy = 0; //for each protein chain for(unsigned int i=0; i<pcs.size(); i++) { res = pcs[i]->getResidues(); for(unsigned int r=0; r<res.size(); r++) entropy += check_residue(res[r], ligand_atoms); } return temperature*entropy*4.184; }
// ---------------------------------------------------------------------- void LocalizationIterLaterationModule:: iter_lateration_step( void ) throw() { if ( state_ == il_finished || !sound_ ) return; if ( iteration_cnt_ >= iteration_limit_ ) state_ = il_finished; ++iteration_cnt_; neighborhood_w().reassign_twins( twin_measure_ * observer().comm_range() ); if ( neighborhood().confident_neighbor_cnt() < min_confident_nbrs_ ) return; Vec est_pos; NeighborInfoList neighbors; collect_neighbors( neighborhood(), lat_confident, neighbors ); // try to update position. if lateration fails, confidence is set to 0, // else position is updated and confidence is set to average of all // neighbor confidences if ( est_pos_lateration( neighbors, est_pos, lat_confident, false ) && est_pos_lateration( neighbors, est_pos, lat_confident, true ) ) { set_confidence( neighborhood().avg_neighbor_confidence() ); // check validity of new position. if check fails, there is a chance // of 'res_acceptance_', which is normally set to 0.1, to accept // the position anyway. this is done to avoid being trapped in a // local minimum. moreover, if the bad position is accepted, the // confidence is reduced by 50%. if ( !check_residue( neighbors, est_pos, lat_confident, observer().comm_range() ) ) { if ( res_acceptance_ > uniform_random_0i_1i() ) set_confidence( observer().confidence() / 2 ); else { if ( observer().confidence() == 0 ) return; set_confidence( 0 ); node_w().clear_est_position(); send( new LocalizationIterLaterationMessage( observer().confidence() ) ); return; } } // check, whether the new position is very close to the old one or // not. if so, refinement is finished. if ( node().has_est_position() ) { double pos_diff = euclidean_distance( est_pos, node().est_position() ); if ( pos_diff < abort_pos_update_ * observer().comm_range() ) state_ = il_finished; } node_w().set_est_position( est_pos ); } else { if ( observer().confidence() == 0 ) return; set_confidence( 0 ); node_w().clear_est_position(); } send( new LocalizationIterLaterationMessage( observer().confidence() ) ); }
void read_pdb(char pdb_name[FILENAME_LEN],int *natoms,int *nresidues, char chain1,char chain2,int by_domain,int domain1) { char line[LINE_LEN +1]; char chain, last_chain; char last_res_name[4], res_name[4]; char last_res_num[6], res_num[6]; int chain_domain; int done, residue_wanted; struct atom *atom_ptr; struct residue *residue_ptr; FILE *fil_pdb; /* Initialise variables */ first_atom_ptr = NULL; last_atom_ptr = NULL; first_residue_ptr = NULL; last_residue_ptr = NULL; *natoms = 0; *nresidues = 0; last_chain = '\0'; last_res_num[0] = '\0'; last_res_name[0] = '\0'; chain = ' '; res_num[0] = '\0'; res_name[0] = '\0'; /* Open the PDB file */ printf("\n\n Opening PDB file [%s] ...",pdb_name); if ((fil_pdb = fopen(pdb_name,"r")) == NULL) { printf("\n*** Unable to open your PDB file [%s]\n",pdb_name); exit(1); } /* Prepare to start reading in the data from the PDB file */ printf("\n"); printf(" Reading through PDB file ...\n"); printf("\n"); done = FALSE; residue_wanted = FALSE; /* Loop while reading through the PDB file */ while (fgets(line,LINE_LEN,fil_pdb) != NULL && done == FALSE) { /* Check if ATOM or HETATM record */ if (!strncmp(line,"ATOM ",6) || !strncmp(line,"HETATM",6)) { /* Extract the residue name, number and chain-id */ strncpy(res_name,line+17,3); res_name[3] = '\0'; strncpy(res_num,line+22,5); res_num[5] = '\0'; chain = line[21]; /* Check whether this is a new residue */ if (chain != last_chain || strncmp(res_num,last_res_num,5) || strncmp(res_name,last_res_name,3)) { /* Determine whether this residue is wanted */ if (!strncmp(res_name,"HOH",3)) { chain_domain = 0; residue_wanted = TRUE; } else { /* Check whether residue belongs to one of the chains or domains in question */ chain_domain = check_residue(res_num,chain,chain1,chain2,by_domain, domain1); if (chain_domain != 0) residue_wanted = TRUE; else residue_wanted = FALSE; } /* If this residue is wanted, then create a record for it */ if (residue_wanted == TRUE) { /* Allocate memory to store this residue's details */ residue_ptr = (struct residue*)malloc(sizeof(struct residue)); if (residue_ptr == NULL) { printf("*** Can't allocate memory for struct"); printf(" residue\n"); exit (1); } /* If this is first residue stored, then update pointer to head of linked list */ if (first_residue_ptr == NULL) first_residue_ptr = residue_ptr; /* Otherwise update previous residue's link so it points to this one*/ else last_residue_ptr->next_residue_ptr = residue_ptr; /* Store details from record read in */ strncpy(residue_ptr->res_name,res_name,3); residue_ptr->res_name[3] = '\0'; strncpy(residue_ptr->res_num,res_num,5); residue_ptr->res_num[5] = '\0'; residue_ptr->chain = chain; /* Store chain/domain to which the residue belongs */ residue_ptr->chain_domain = chain_domain; residue_ptr->interacting = FALSE; /* Store pointer to this residue's first atom */ residue_ptr->first_atom_ptr = NULL; residue_ptr->num_atoms = 0; /* Set next residue pointer to null */ residue_ptr->next_residue_ptr = NULL; /* Save current residue's pointer as last residue's pointer */ last_residue_ptr = residue_ptr; /* Increment count of residues */ (*nresidues)++; } /* Store the current residue number, name and chain ID */ strncpy(last_res_num,res_num,5); last_res_num[5] = '\0'; strncpy(last_res_name,res_name,5); last_res_name[3] = '\0'; last_chain = chain; } /* If current residue is wanted, then store this atom */ if (residue_wanted == TRUE) { /* Allocate memory to store this atom's details */ atom_ptr = (struct atom*)malloc(sizeof(struct atom)); if (atom_ptr == NULL) { printf("*** Can't allocate memory for struct"); printf(" atom\n"); exit (1); } /* If this is first atom stored, then update pointer to head of linked list */ if (first_atom_ptr == NULL) first_atom_ptr = atom_ptr; /* Otherwise update previous atom's link so it points to this one*/ else last_atom_ptr->next_atom_ptr = atom_ptr; /* Store details from records read in */ strncpy(atom_ptr->label,line,6); atom_ptr->label[6] = '\0'; sscanf(line+6,"%5d",&(atom_ptr->atom_number)); strncpy(atom_ptr->atom_name,line+12,4); atom_ptr->atom_name[4]='\0'; sscanf(line+30,"%f%f%f ",&atom_ptr->x,&atom_ptr->y,&atom_ptr->z); strncpy(atom_ptr->occupancy,line+54,6); atom_ptr->occupancy[6] = '\0'; strncpy(atom_ptr->bvalue,line+60,6); atom_ptr->bvalue[6] = '\0'; /* Store pointer to current residue */ atom_ptr->residue_ptr = residue_ptr; /* Set next atom pointer to null */ atom_ptr->next_atom_ptr = NULL; /* Save current atom's pointer as last atom pointer */ last_atom_ptr = atom_ptr; /* Increment count of atoms belonging to this residue */ residue_ptr->num_atoms++; /* If this is the first atom of this residue, store its pointer */ if (residue_ptr->first_atom_ptr == NULL) residue_ptr->first_atom_ptr = atom_ptr; } /* Increment count of atoms */ (*natoms)++; } /* If this is a MODEL or ENDMDL record, and already have read in at least one atom, then want to end here */ else if (!strncmp(line,"MODEL ",6) || !strncmp(line,"ENDMDL",6)) { /* Check that have at least one atom and residue */ if (*natoms > 0 && *nresidues > 0) done = TRUE; } } /* Close the PDB file */ fclose(fil_pdb); }