Esempio n. 1
0
	void RotLibConvert_Dunbrack_BBInd::readDefinition( StringBuilder& sb, RotamerLibrary& _RotLib ) const
	{
		ASSERT( sb.size() >= 67, ParseException, "String too short to parse!!");

		StringBuilder resname(3);
		resname.setTo( sb, 0, 3 );
		sb.TruncateLeftBy(18);

		int pdbCount = sb.parseInt(0,7);
		if( pdbCount == 0 )
			return;
		double probability = sb.parseDouble(7,8);
		sb.TruncateLeftBy(37);
		
		std::vector<double> importChis;
		std::vector<std::string> parts = sb.tokenise();
		ASSERT( (parts.size() % 2 == 0), ParseException, "Unexpected element count");

		for( size_t i = 0; i < parts.size(); i+=2 )
		{
			double chi;
			ASSERT( 0 == str2double( parts[i], chi ), ParseException, "Error parsing chi def");
			importChis.push_back(Maths::DegToRad(chi));
		}

		ASSERT( importChis.size() != 0, ParseException, "No chis found!!");
		_RotLib.addRotamer( resname.toString(), importChis, ConstantProbability( probability ) );
	}
Esempio n. 2
0
int main(int argc, char** argv){
  
  if (argc != 3 ){
    std::cerr << "Please provide a filename and a residue name"  << std::endl;  
    return EXIT_FAILURE;
  }
  
  //creates one system with all atoms matching the criteria
  std::string resname(argv[2]);
  ESBTL::Select_by_resname selector(resname);
  ESBTL::Generic_line_selector<ESBTL::Select_by_resname> sel(selector);
  
  std::vector<ESBTL::Default_system> systems;
  //declare the building that will contruct the system from the pdb file.
  
  std::cout << sel.max_nb_systems() << std::endl;
  
  ESBTL::All_atom_system_builder<ESBTL::Default_system> builder(systems,sel.max_nb_systems());
  
  //read the pdb file
  if (ESBTL::read_a_pdb_file(argv[1],sel,builder,Accept_none_occupancy_policy())){
    if ( systems.empty() || systems[0].has_no_model() ){
      std::cerr << "No atoms found" << std::endl;
      return EXIT_FAILURE;
    }
    //consider the first model of the system
    const ESBTL::Default_system::Model& model=*systems[0].models_begin();
    
    std::cout << model.number_of_atoms() << " atoms in residue(s) named " << resname << std::endl;
  }
  else
    return EXIT_FAILURE;
  
  return EXIT_SUCCESS;
}
Esempio n. 3
0
// PDBfile::pdb_Residue()
NameType PDBfile::pdb_Residue(int& current_res) {
  // Res name (16-20)
  char savechar = linebuffer_[20];
  linebuffer_[20] = '\0';
  NameType resname(linebuffer_+16);
  // Replace asterisks with single quotes
  resname.ReplaceAsterisk();
  linebuffer_[20] = savechar;
  // Res num (22-27)
  savechar = linebuffer_[27];
  linebuffer_[27] = '\0';
  current_res = atoi( linebuffer_+22 );
  linebuffer_[27] = savechar;
  return resname;
}
Esempio n. 4
0
uint16 ResMan_t7g::getRef(Common::String name, Common::String scriptname) {
	// Get the name of the RL file
	Common::String rlFileName(t7g_gjds[_lastGjd]);
	rlFileName += ".rl";

	Common::SeekableReadStream *rlFile = 0;

	if (_macResFork) {
		// Open the RL file from the resource fork
		rlFile = _macResFork->getResource(rlFileName);
	} else {
		// Open the RL file
		rlFile = SearchMan.createReadStreamForMember(rlFileName);
	}

	if (!rlFile)
		error("Groovie::Resource: Couldn't open %s", rlFileName.c_str());

	uint16 resNum;
	bool found = false;
	for (resNum = 0; !found && !rlFile->err() && !rlFile->eos(); resNum++) {
		// Read the resource name
		char readname[12];
		rlFile->read(readname, 12);

		// Test whether it's the resource we're searching
		Common::String resname(readname, 12);
		if (resname.hasPrefix(name.c_str())) {
			debugC(2, kGroovieDebugResource | kGroovieDebugAll, "Groovie::Resource: Resource %12s matches %s", readname, name.c_str());
			found = true;
		}

		// Skip the rest of resource information
		rlFile->read(readname, 8);
	}

	// Close the RL file
	delete rlFile;

	// Verify we really found the resource
	if (!found) {
		error("Groovie::Resource: Couldn't find resource %s in %s", name.c_str(), rlFileName.c_str());
		return (uint16)-1;
	}

	return (_lastGjd << 10) | (resNum - 1);
}
Esempio n. 5
0
chain_class::chain_class(FFF* P,vector<string> lines): _P(P) {
  //printf ("\nLines passed to chain_class:\n");
  string last_resnum="DUMMY";
  vector<string> residue_lines;
  //
  // Get the chain name
  //
  string chainid(lines[0],21,1);
    //printf ("ChainID in chain_class: '%s'\n",chainid.c_str());
  name=strip(chainid);
  for (unsigned int ii=0;ii<lines.size();ii++) {
    //
    // Get the residue name and number
    //
    string resname(lines[ii],17,3);
    string resnum(lines[ii],22,5);
    if (resnum!=last_resnum) {
      //
      // new residue
      //
      if (last_resnum!="DUMMY") {
          //printf ("Instantiating residue_class\n");
	residue_class X(this,residue_lines);
          //printf ("done resclass\n");
	residues.push_back(X);
	residue_lines.resize(0);
      }
      last_resnum=resnum;
    }
    residue_lines.push_back(lines[ii]);
  }
  //
  // And the last residue...
  //
  if (residue_lines.size()!=0) {
    residue_class X(this,residue_lines);
    residues.push_back(X);
  }
  //printf("Chain name: %s found\n",name.c_str());
  return;
}
Esempio n. 6
0
int main(int argc,char*argv[])
{
	if(argc!=2)
	{
		cout<<"USAGE:SIS datafile  "<<endl;
		exit(1);
	}
	//define the entry

	string networkname(argv[1]); //network name

	double a=1;
	double alpha=0.4;
	double beta=0.1;
	int game_rounds=500; //MC rounds
	int aver_rounds=10;  //do average
	double delta=1;//delta


	string output_name_pre;  //the network name 
	for(int i=0;i!=networkname.size()-4;i++)
	{
		output_name_pre.push_back(networkname[i]);
	}

	//random generator
	//to initialize the random seed
	igraph_rng_init(mrng,&igraph_rngtype_mt19937);

	unsigned long idum;  // random number seed
	idum=(unsigned long)time(NULL);
	igraph_rng_seed(mrng,idum);

	//construct the graph
	igraph_t network;
   
	gen_graph(&network,networkname);
	int nwsize=igraph_vcount(&network);  //the size of the network
   
   
	//to generate the name of the output file
	//output file name
	string resname("res.txt");
	string totalname=output_name_pre+resname;	
	FILE *outfile;
	outfile = fopen(totalname.c_str(), "w");
	
	//construct the population
	for(a=-6;a<6.1;a+=0.1 )
	{
		population popu(output_name_pre,&network,delta,0.01,a,2,3*nwsize,3*nwsize);
		double res=0;
		popu.population_dynamics(&res,alpha,beta,1000);
		fprintf(outfile,"%f\t%f\n",a,res/ nwsize);
		fflush(outfile);
	}
	fclose(outfile);
/*  
	igraph_t network;
	int nwsize = igraph_vcount(&network);  //the size of the network
	igraph_watts_strogatz_game(&network, 1, 500, 4, 0.1, false, false);
	string output_name_pre("small_world");
	population test(output_name_pre,&network, 1, 0.01, 1, 0, 3 * nwsize, 3 * nwsize);
	test.initial_state();

	double res = 0;

	test.population_dynamics(&res,0.3,0.1,300);
*/
	//for (a=-5;a!=5;a+=0.2)
	//
	//{

 //       population test(&network,delta,0.01,a,type,3*nwsize,3*nwsize);
	//	vector<double> average_rres;

	//	for(int i=0;i!=aver_rounds;++i)
	//	{
	//		double rres=0;
	//		test.initial_state();
	//		test.population_dynamics(&rres,0.4,0.1,game_rounds);
	////		printf("%f\n", rres);
	//		average_rres.push_back(rres);

	//	}
	//	fprintf(outfile,"%f\t%f\n",a,double (accumulate(average_rres.begin(),\
	//		average_rres.end(),0)/average_rres.size()));
	//	fflush(outfile);
	//}
	//fclose(outfile);
	igraph_destroy(&network);
	return 0;
}
Esempio n. 7
0
std::string Condition::getName(bool tip, NameFlags::Value flags, int recursion) const
{
    if (!tip) {
	    return (type < scen.pergame->max_condition_types) ? types[type] : "Unknown!";
	} else {
	    std::string stype = std::string("");
        std::ostringstream convert;
        switch (type) {
        case ConditionType::None:
            // Let this act like a separator
            convert << "                                                                                    ";
            stype.append(convert.str());
            break;
        case ConditionType::BringObjectToArea:
            convert << get_unit_full_name(object) << " " << object;
            convert << " is" << areaName();
            stype.append(convert.str());
            break;
        case ConditionType::BringObjectToObject:
            convert << get_unit_full_name(object) << " " << object << " is next to unit " << get_unit_full_name(u_loc) << " " << u_loc;
            stype.append(convert.str());
            break;
        case ConditionType::OwnObjects:
        case ConditionType::OwnFewerObjects:
        case ConditionType::ObjectsInArea:
            { // we define some variables in this block, therefore need scope as we are also in a case
                if (valid_player()) {
                    convert << playerPronoun(player) << " has ";
                }
                switch (type) {
                case ConditionType::OwnObjects:
                case ConditionType::ObjectsInArea:
                    if (amount == 0) {
                        convert << "any number of";
                    } else {
                        convert << "at least " << amount;
                    }
                    break;
                case ConditionType::OwnFewerObjects:
                    if (amount == 0) {
                        convert << "no";
                    } else {
                        convert << "at most " << amount;
                    }
                    break;
                }
                if (valid_unit_spec()) {
                    std::string un(wstringToString(pUnit->name()));
                    if (amount > 1 && !un.empty() && *un.rbegin() != 's' && !replaced(un, "man", "men")) {
                        convert << " " << un << "s";
                    } else {
                        convert << " " << un;
                    }
                } else {
                    if (amount != 1) {
                        convert << " units";
                    } else {
                        convert << " unit";
                    }
                }
                convert << areaName();
                stype.append(convert.str());
            }
            break;
        case ConditionType::DestroyObject:
            convert << get_unit_full_name(object) << " is killed";
            stype.append(convert.str());
            break;
        case ConditionType::CaptureObject:
            convert << playerPronoun(player) << " captured " << get_unit_full_name(object);
            stype.append(convert.str());
            break;
        case ConditionType::AccumulateAttribute:
            switch (res_type) {
            case 0: // Food accumulated
                convert << playerPronoun(player) << " has " << amount << " food";
                break;
            case 1: // Wood accumulated
                convert << playerPronoun(player) << " has " << amount << " wood";
                break;
            case 2: // Stone accumulated
                convert << playerPronoun(player) << " has " << amount << " stone";
                break;
            case 3: // Gold accumulated
                convert << playerPronoun(player) << " has " << amount << " gold";
                break;
            case 20: // Units killed
                if (amount == 1) {
                    convert << playerPronoun(player) << " kills a unit";
                } else {
                    convert << playerPronoun(player) << " has killed " << amount << " units";
                }
                break;
            case 44: // Kill ratio
                if (amount == 0) {
                    convert << playerPronoun(player) << " has equal kills and deaths";
                } else if (amount == 1) {
                    convert << playerPronoun(player) << " has killed one more than lost";
                } else if (amount > 0) {
                    convert << playerPronoun(player) << " has " << amount << " more kills than deaths";
                } else if (amount == -1) {
                    convert << playerPronoun(player) << " has lost one more unit than has killed";
                } else {
                    convert << playerPronoun(player) << " has " << -amount << " more deaths than kills";
                }
                break;
            default:
                //convert << types_short[type];
                if (res_type >= 0) {
                    const Link * list = esdata.resources.head();
	                for (int i=0; list; list = list->next(), i++)
	                {
		                if (i == res_type) {
                            std::wstring resname(list->name());
		                    convert << playerPronoun(player) << "'s ";
                            convert << std::string( resname.begin(), resname.end());
                            convert << " >= " << amount;
		                    break;
		                }
	                }
	            }
                break;
            }
            stype.append(convert.str());
            break;
        case ConditionType::ResearchTehcnology:
            if (valid_technology_spec()) {
                convert << playerPronoun(player) << " has tech ";
                std::wstring techname(pTech->name());
                convert << std::string( techname.begin(), techname.end());
                convert << " researched";
            } else {
                convert << "INVALID";
            }
            stype.append(convert.str());
            break;
        case ConditionType::ResearchingTechnology:
            if (pTech && pTech->id()) {
                convert << playerPronoun(player) << " is researching ";
                std::wstring techname(pTech->name());
                convert << std::string( techname.begin(), techname.end());
            } else {
                convert << "INVALID";
            }
            stype.append(convert.str());
            break;
        case ConditionType::Timer:
            convert << time_string(timer) << " has passed";
            stype.append(convert.str());
            break;
        case ConditionType::ObjectSelected:
            convert << "selected unit " << object;
            convert << " (" << get_unit_full_name(object) << ")";
            stype.append(convert.str());
            break;
        case ConditionType::AISignal:
            switch (ai_signal) {
            case -1034:
                convert << "singleplayer / cheats enabled";
                break;
            case -1036:
                convert << "starting resources set to standard";
                break;
            case -1039:
                convert << "regicide";
                break;
            case -1040:
                convert << "deathmatch";
                break;
            case -70850:
                convert << "one-click garrison";
                break;
            default:
                if (ai_signal >= -518 && ai_signal <= -7) {
                    int signal = ai_signal + 518;
                    int taunt_player = signal / 64;
                    int taunt_set_id = signal % 64;
                    convert << "player " << taunt_player + 1 << " taunted " << taunt_set[taunt_set_id];
                } else if (ai_signal >= -774 && ai_signal <= -519) {
                    convert << "AI goal " << ai_signal + 774 << " achieved";
                } else {
                    convert << "AI signalled " << ai_signal;
                }
            }
            stype.append(convert.str());
            break;
        case ConditionType::ObjectVisible:
            convert << "unit " << object;
            convert << " (" << get_unit_full_name(object) << ") is visible";
            stype.append(convert.str());
            break;
        case ConditionType::PlayerDefeated:
            if (player == 0) {
                convert << "Gaia";
            } else {
                convert << playerPronoun(player);
            }
            convert << " is defeated";
            stype.append(convert.str());
            break;
        case ConditionType::ObjectHasTarget:
            convert << "unit " << object << " (" << get_unit_full_name(object) << ") is targetting";
            if (null_location_unit()) {
                convert << " something";
            } else {
                convert << " " << u_loc << " (" << get_unit_full_name(u_loc) << ")";
            }
            stype.append(convert.str());
            break;
        case ConditionType::UnitsGarrisoned:
            if (amount == 1) {
                convert << "unit " << object << " (" << get_unit_full_name(object) << ") has " << amount << " units garrisoned";
            } else {
                convert << "unit " << object << " (" << get_unit_full_name(object) << ") has one unit garrisoned";
            }
            stype.append(convert.str());
            break;
        case ConditionType::DifficultyLevel:
            convert << "difficulty is ";
            switch (amount) {
            case DifficultyLevel::Hardest:
                convert << "Hardest";
                break;
            case DifficultyLevel::Hard:
                convert << "Hard";
                break;
            case DifficultyLevel::Moderate:
                convert << "Moderate";
                break;
            case DifficultyLevel::Standard:
                convert << "Standard";
                break;
            case DifficultyLevel::Easiest:
                convert << "Easiest";
                break;
            }
            stype.append(convert.str());
            break;
        case ConditionType::UnitsQueuedPastPopCap_SWGB:
            if (valid_player()) {
                convert << playerPronoun(player) << " has " << amount << " units queued past the pop cap";
            } else {
                convert << "INVALID";
            }
            stype.append(convert.str());
            break;
        case ConditionType::OwnFewerFoundations_SWGB: // Chance_HD:
            switch (scen.game) {
            case AOHD:
            case AOF:
            case AOHD4:
            case AOF4:
            case AOHD6:
            case AOF6:
                convert << amount << "% chance ";
                stype.append(convert.str());
                break;
            case SWGB:
            case SWGBCC:
                if (valid_player()) {
                    convert << playerPronoun(player) << " has ";
                }
                if (amount == 0) {
                    convert << "no";
                } else {
                    convert << "at most " << amount;
                }
                if (valid_unit_spec()) {
                    std::string un(wstringToString(pUnit->name()));
                    if (amount > 1 && !un.empty() && *un.rbegin() != 's' && !replaced(un, "man", "men")) {
                        convert << " " << un << " foundations";
                    } else {
                        convert << " " << un << " foundation";
                    }
                } else {
                    if (amount != 1) {
                        convert << " foundations";
                    } else {
                        convert << " foundation";
                    }
                }
                convert << areaName();
                stype.append(convert.str());
                break;
            default:
                convert << amount << "UNKNOWN CONDITION";
                stype.append(convert.str());
            }
            break;
        default:
            stype.append((type < scen.pergame->max_condition_types) ? types_short[type] : "Unknown!");
        }

        return flags&NameFlags::LIMITLEN?stype.substr(0,MAX_CHARS):stype;
    }
}