Example #1
0
void User::Save()
{
	CCFileUtils* fileUtils = CCFileUtils::sharedFileUtils();
	bugsCatched->writeToFile("BugsCatched.plist");
	item->writeToFile("Item.plist");
	string writablePath = fileUtils->getWritablePath() + "User.txt";
	FILE *fp = fopen(writablePath.c_str(), "w");
	string data = name + "\n" + ConvertInt(score) + "\n" + ConvertInt(level);
	fputs(data.c_str(), fp);
	fclose(fp);
}
Example #2
0
bool CSPropDebyeMaterial::ReadFromXML(TiXmlNode &root)
{
	if (CSPropDispersiveMaterial::ReadFromXML(root)==false) return false;
	TiXmlElement* prop=root.ToElement();

	if (prop==NULL) return false;

	// count m_Order
	TiXmlElement* matProp=prop->FirstChildElement("Property");
	if (matProp!=NULL)
	{
		m_Order=1;
		while (1)
		{
			if (matProp->Attribute("EpsilonDelta_"+ConvertInt(m_Order+1)))
				++m_Order;
			else if (matProp->Attribute("MueDelta_"+ConvertInt(m_Order+1)))
				++m_Order;
			else
				break;
		}
	}
	else
		return false;

	InitValues();

	if (ReadVectorTerm(EpsDelta[0],*matProp,"EpsilonDelta_1",0.0)==false)
		ReadVectorTerm(EpsDelta[0],*matProp,"EpsilonDelta",0.0);

	if (ReadVectorTerm(EpsRelaxTime[0],*matProp,"EpsilonRelaxTime_1",0.0)==false)
		ReadVectorTerm(EpsRelaxTime[0],*matProp,"EpsilonRelaxTime",0.0);

	TiXmlElement* weightProp=prop->FirstChildElement("Weight");
	if (weightProp)
	{
		if (ReadVectorTerm(WeightEpsDelta[0],*weightProp,"EpsilonDelta_1",1.0)==false)
			ReadVectorTerm(WeightEpsDelta[0],*weightProp,"EpsilonDelta",1.0);

		if (ReadVectorTerm(WeightEpsRelaxTime[0],*weightProp,"EpsilonRelaxTime_1",1.0)==false)
			ReadVectorTerm(WeightEpsRelaxTime[0],*weightProp,"EpsilonRelaxTime",1.0);
	}

	for (int o=1;o<m_Order;++o)
	{
		ReadVectorTerm(EpsDelta[o],*matProp,"EpsilonDelta_"+ConvertInt(o+1),0.0);

		ReadVectorTerm(EpsRelaxTime[o],*matProp,"EpsilonRelaxTime_"+ConvertInt(o+1),0.0);

		if (weightProp)
		{
			ReadVectorTerm(WeightEpsDelta[o],*weightProp,"EpsilonDelta_"+ConvertInt(o+1),1.0);

			ReadVectorTerm(WeightEpsRelaxTime[o],*weightProp,"EpsilonRelaxTime_"+ConvertInt(o+1),1.0);
		}
	}
	return true;
}
Example #3
0
void User::CatchBug(Bug* bug)
{
	string x = bug->getId();
	if (bugsCatched->objectForKey(x) != NULL)
	{
		CCString* count = (CCString*)bugsCatched->valueForKey(x);
		int increase = count->floatValue() + 1;
		CCString* add = CCString::create(ConvertInt(increase));
		bugsCatched->setObject(add,x);
	}
	else
	{
		CCString* count = CCString::create("1");
		bugsCatched->setObject(count,x);
	}
}
Example #4
0
bool CSPropDebyeMaterial::Write2XML(TiXmlNode& root, bool parameterised, bool sparse)
{
	if (CSPropDispersiveMaterial::Write2XML(root,parameterised,sparse) == false) return false;
	TiXmlElement* prop=root.ToElement();
	if (prop==NULL) return false;

	string suffix;
	for (int o=0;o<m_Order;++o)
	{
		suffix = ConvertInt(o+1);
		TiXmlElement* value=prop->FirstChildElement("Property");
		if (value==NULL)
			return false;
		WriteVectorTerm(EpsDelta[o],*value,"EpsilonDelta_"+suffix,parameterised);
		WriteVectorTerm(EpsRelaxTime[o],*value,"EpsilonRelaxTime_"+suffix,parameterised);

		TiXmlElement* weight=prop->FirstChildElement("Weight");
		if (weight==NULL)
			return false;
		WriteVectorTerm(WeightEpsDelta[o],*weight,"EpsilonDelta_"+suffix,parameterised);
		WriteVectorTerm(WeightEpsRelaxTime[o],*weight,"EpsilonRelaxTime_"+suffix,parameterised);
	}
	return true;
}
	//--
	bool DataProperty::Satisfy(OpenBabel::OBBond* pBond, 
								const std::string& refTo, 
								std::vector<Class*>& vecSatisfiedClasses, 
								std::string& refValue)
	{
		//bool bSatisfied = false;
		int iPosition = -1;

		// [rad] if we are default, we automatically satisfy		
		if(!IsDefault())
		{			
			if(!SatisfyCommon(vecSatisfiedClasses, iPosition))
			{
				// [rad] this property does not apply

				refValue = "";
				return(false);
			}
		}

		// [rad] go through possible data types..

		if(!refTo.compare("BOND_ORDER"))
		{
			ConvertInt(pBond->GetBondOrder(), refValue);
		}
		else if(!refTo.compare("BOND_EQUILIBRIUM_LENGTH"))
		{
			ConvertDouble(pBond->GetEquibLength(), refValue);
		}
		else if(!refTo.compare("BOND_LENGTH"))
		{
			ConvertDouble(pBond->GetLength(), refValue);
		}
		else if(!refTo.compare("BOND_IS_AROMATIC"))
		{
			ConvertBool(pBond->IsAromatic(), refValue);
		}
		else if(!refTo.compare("BOND_IS_IN_RING"))
		{
			ConvertBool(pBond->IsInRing(), refValue);
		}
		else if(!refTo.compare("BOND_IS_ROTOR"))
		{
			ConvertBool(pBond->IsRotor(), refValue);
		}
		else if(!refTo.compare("BOND_IS_AMIDE"))
		{
			ConvertBool(pBond->IsAmide(), refValue);
		}
		else if(!refTo.compare("BOND_IS_PRIMARY_AMIDE"))
		{
			ConvertBool(pBond->IsPrimaryAmide(), refValue);
		}
		else if(!refTo.compare("BOND_IS_SECONDARY_AMIDE"))
		{
			ConvertBool(pBond->IsSecondaryAmide(), refValue);
		}
		else if(!refTo.compare("BOND_IS_ESTER"))
		{
			ConvertBool(pBond->IsEster(), refValue);
		}
		else if(!refTo.compare("BOND_IS_CARBONYL"))
		{
			ConvertBool(pBond->IsCarbonyl(), refValue);
		}
		else if(!refTo.compare("BOND_IS_SINGLE_BOND"))
		{
			ConvertBool(pBond->IsSingle(), refValue);
		}
		else if(!refTo.compare("BOND_IS_DOUBLE_BOND"))
		{
			ConvertBool(pBond->IsDouble(), refValue);
		}
		else if(!refTo.compare("BOND_IS_TRIPLE_BOND"))
		{
			ConvertBool(pBond->IsTriple(), refValue);
		}
		else if(!refTo.compare("BOND_IS_CLOSURE_BOND"))
		{
			ConvertBool(pBond->IsClosure(), refValue);
		}
		else if(!refTo.compare("BOND_IS_UP"))
		{
			ConvertBool(pBond->IsUp(), refValue);
		}
		else if(!refTo.compare("BOND_IS_DOWN"))
		{
			ConvertBool(pBond->IsDown(), refValue);
		}
		else if(!refTo.compare("BOND_IS_HASH"))
		{
			ConvertBool(pBond->IsHash(), refValue);
		}
		else if(!refTo.compare("BOND_IS_WEDGE"))
		{
			ConvertBool(pBond->IsWedge(), refValue);
		}
		else
		{
			// [rad] unknown datatype?
			refValue = "";
			return(false);
		}

		return(true);
	}
	//--
	bool DataProperty::Satisfy(OpenBabel::OBAtom* pAtom, 
								const std::string& refTo, 
								std::vector<Class*>& vecSatisfiedClasses, 
								std::string& refValue)
	{
		//bool bSatisfied = false;
		int iPosition = -1;

		// [rad] if we are default, we automatically satisfy		
		if(!IsDefault())
		{			
			if(!SatisfyCommon(vecSatisfiedClasses, iPosition))
			{
				// [rad] this property does not apply

				refValue = "";
				return(false);
			}
		}

		// [rad] go through possible data types..

		if(!refTo.compare("ATOM_ATOMIC_NUMBER"))
		{
			ConvertInt(pAtom->GetAtomicNum(), refValue);
		}
		else if(!refTo.compare("ATOM_FORMAL_CHARGE"))
		{
			ConvertInt(pAtom->GetFormalCharge(), refValue);
		}
		else if(!refTo.compare("ATOM_ISOTOPE"))
		{
			ConvertInt(pAtom->GetIsotope(), refValue);
		}
		else if(!refTo.compare("ATOM_SPIN_MULTIPLICITY"))
		{
			ConvertInt(pAtom->GetSpinMultiplicity(), refValue);
		}
		else if(!refTo.compare("ATOM_ATOMIC_MASS"))
		{
			ConvertDouble(pAtom->GetAtomicMass(), refValue);
		}
		else if(!refTo.compare("ATOM_EXACT_MASS"))
		{
			ConvertDouble(pAtom->GetExactMass(), refValue);
		}
		else if(!refTo.compare("ATOM_INTERNAL_INDEX"))
		{
			ConvertInt(pAtom->GetIdx(), refValue);
		}
		else if(!refTo.compare("ATOM_VALENCE"))
		{
			ConvertInt(pAtom->GetValence(), refValue);
		}
		else if(!refTo.compare("ATOM_HYBRIDIZATION"))
		{
			ConvertInt(pAtom->GetHyb(), refValue);
		}
		else if(!refTo.compare("ATOM_IMPLICIT_VALENCE"))
		{
			ConvertInt(pAtom->GetImplicitValence(), refValue);
		}
		else if(!refTo.compare("ATOM_HEAVY_VALENCE"))
		{
			ConvertInt(pAtom->GetHvyValence(), refValue);
		}
		else if(!refTo.compare("ATOM_HETERO_VALENCE"))
		{
			ConvertInt(pAtom->GetHeteroValence(), refValue);
		}
		else if(!refTo.compare("ATOM_COORDINATE_X"))
		{
			ConvertDouble(pAtom->GetX(), refValue);
		}
		else if(!refTo.compare("ATOM_COORDINATE_Y"))
		{
			ConvertDouble(pAtom->GetY(), refValue);
		}
		else if(!refTo.compare("ATOM_COORDINATE_Z"))
		{
			ConvertDouble(pAtom->GetZ(), refValue);
		}
		else if(!refTo.compare("ATOM_PARTIAL_CHARGE"))
		{
			ConvertDouble(pAtom->GetPartialCharge(), refValue);
		}
		else if(!refTo.compare("ATOM_FREE_OXYGEN_COUNT"))
		{
			ConvertInt(pAtom->CountFreeOxygens(), refValue);
		}
		else if(!refTo.compare("ATOM_IMPLICIT_HYDROGEN_COUNT"))
		{
			ConvertInt(pAtom->ImplicitHydrogenCount(), refValue);
		}
		else if(!refTo.compare("ATOM_PARTICIPANT_RING_COUNT"))
		{
			ConvertInt(pAtom->MemberOfRingCount(), refValue);
		}
		else if(!refTo.compare("ATOM_AVERAGE_BOND_ANGLE"))
		{
			ConvertDouble(pAtom->AverageBondAngle(), refValue);
		}
		else if(!refTo.compare("ATOM_SMALLEST_BOND_ANGLE"))
		{
			ConvertDouble(pAtom->SmallestBondAngle(), refValue);
		}
		else if(!refTo.compare("ATOM_IS_IN_RING"))
		{
			ConvertBool(pAtom->IsInRing(), refValue);
		}
		else if(!refTo.compare("ATOM_IS_HETERO_ATOM"))
		{
			ConvertBool(pAtom->IsHeteroatom(), refValue);
		}
		else if(!refTo.compare("ATOM_IS_AROMATIC"))
		{
			ConvertBool(pAtom->IsAromatic(), refValue);
		}
		else if(!refTo.compare("ATOM_IS_CHIRAL"))
		{
			ConvertBool(pAtom->IsChiral(), refValue);
		}
		else if(!refTo.compare("ATOM_HAS_SINGLE_BOND"))
		{
			ConvertBool(pAtom->HasSingleBond(), refValue);
		}
		else if(!refTo.compare("ATOM_HAS_DOUBLE_BOND"))
		{
			ConvertBool(pAtom->HasDoubleBond(), refValue);
		}
		else if(!refTo.compare("ATOM_HAS_TRIPLE_BOND"))
		{
			ConvertBool(pAtom->HasBondOfOrder(3), refValue);
		}		
		else if(!refTo.compare("ATOM_HAS_AROMATIC_BOND"))
		{
			ConvertBool(pAtom->HasAromaticBond(), refValue);
		}		
		else if(!refTo.compare("ATOM_SINGLE_BOND_COUNT"))
		{
			ConvertInt(pAtom->CountBondsOfOrder(1), refValue);
		}
		else if(!refTo.compare("ATOM_DOUBLE_BOND_COUNT"))
		{
			ConvertInt(pAtom->CountBondsOfOrder(2), refValue);
		}
		else if(!refTo.compare("ATOM_TRIPLE_BOND_COUNT"))
		{
			ConvertInt(pAtom->CountBondsOfOrder(3), refValue);
		}
		else if(!refTo.compare("ATOM_AROMATIC_BOND_COUNT"))
		{
			ConvertInt(pAtom->CountBondsOfOrder(5), refValue);
		}
		else if(!refTo.compare("ATOM_BOND_COUNT"))
		{
			//return(ConvertInt(pAtom->CountBondsOfOrder(5)));
			OpenBabel::OBBond* pBond;
			std::vector<OpenBabel::OBEdgeBase*>::iterator iter_bond;
			int iCount = 0;

			for(pBond = pAtom->BeginBond(iter_bond); pBond; pBond = pAtom->NextBond(iter_bond))
			{
				iCount++;
			}
	
			ConvertInt(iCount, refValue);
		}
		else
		{
			// [rad] unknown datatype?
			refValue = "";
			return(false);
		}

		return(true);
	}
	//--
	bool DataProperty::Satisfy(OpenBabel::OBMol* pMolecule, 
									const std::string& refTo, 
									std::vector<Class*>& vecSatisfiedClasses, 
									std::string& refValue)
	{
		//bool bSatisfied = false;
		int iPosition = -1;

		// [rad] if we are default, we automatically satisfy		
		if(!IsDefault())
		{			
			if(!SatisfyCommon(vecSatisfiedClasses, iPosition))
			{
				// [rad] this property does not apply

				refValue = "";
				return(false);
			}
		}

		// [rad] go through possible data types..

		if(!refTo.compare("MOLECULE_ATOM_COUNT"))
		{
			ConvertInt(pMolecule->NumAtoms(), refValue);
		}
		else if(!refTo.compare("MOLECULE_BOND_COUNT"))
		{
			ConvertInt(pMolecule->NumBonds(), refValue);
		}
		else if(!refTo.compare("MOLECULE_RING_COUNT"))
		{
			std::vector<OpenBabel::OBRing*>& refSSSR = pMolecule->GetSSSR();
			ConvertInt(refSSSR.size(), refValue);
		}
		else if(!refTo.compare("MOLECULE_HEAVY_HYDROGEN_COUNT"))
		{
			ConvertInt(pMolecule->NumHvyAtoms(), refValue);
		}
		else if(!refTo.compare("MOLECULE_RESIDUE_COUNT"))
		{
			ConvertInt(pMolecule->NumResidues(), refValue);
		}
		else if(!refTo.compare("MOLECULE_ROTOR_COUNT"))
		{
			ConvertInt(pMolecule->NumRotors(), refValue);
		}
		else if(!refTo.compare("MOLECULE_FORMULA"))
		{
			refValue = pMolecule->GetFormula();
		}
		else if(!refTo.compare("MOLECULE_FORMATION_HEAT"))
		{
			ConvertDouble(pMolecule->GetEnergy(), refValue);
		}
		else if(!refTo.compare("MOLECULE_STANDARD_MOLAR_MASS"))
		{
			ConvertDouble(pMolecule->GetMolWt(), refValue);
		}
		else if(!refTo.compare("MOLECULE_EXACT_MASS"))
		{
			ConvertDouble(pMolecule->GetExactMass(), refValue);
		}
		else if(!refTo.compare("MOLECULE_TOTAL_CHARGE"))
		{
			ConvertInt(pMolecule->GetTotalCharge(), refValue);
		}
		else if(!refTo.compare("MOLECULE_SPIN_MULTIPLICITY"))
		{
			ConvertInt(pMolecule->GetTotalSpinMultiplicity(), refValue);
		}
		else if(!refTo.compare("MOLECULE_IS_CHIRAL"))
		{
			ConvertBool(pMolecule->IsChiral(), refValue);
		}
		else if(!refTo.compare("MOLECULE_HAS_AROMATIC_RING"))
		{
			std::vector<OpenBabel::OBRing*>& refSSSR = pMolecule->GetSSSR();
			bool bAromatic = false;
			std::vector<OpenBabel::OBRing*>::iterator iter_rings = refSSSR.begin();
			while(iter_rings != refSSSR.end())
			{
				if((*iter_rings)->IsAromatic())
				{
					bAromatic = true;
					break;
				}

				iter_rings++;
			}

			ConvertBool(bAromatic, refValue);
		}
		else if(!refTo.compare("MOLECULE_HAS_HOMOCYCLIC_RING"))
		{
			std::vector<OpenBabel::OBRing*>& refSSSR = pMolecule->GetSSSR();
			std::vector<OpenBabel::OBRing*>::iterator iter_rings = refSSSR.begin();
			OpenBabel::OBAtom* pAtom;

			bool bHomoCyclic = true;

			while(iter_rings != refSSSR.end())
			{
				std::vector<int>::iterator iter_path = (*iter_rings)->_path.begin();
				while(iter_path != (*iter_rings)->_path.end())
				{
					pAtom = pMolecule->GetAtom((*iter_path));

					if(pAtom)
					{
						if(6 != pAtom->GetAtomicNum())
						{
							bHomoCyclic = false;
							break;
						}
					}

					iter_path++;
				}

				if(!bHomoCyclic) break;

				iter_rings++;
			}
		
			ConvertBool(bHomoCyclic, refValue);
		}
		else if(!refTo.compare("MOLECULE_HAS_HETEROCYCLIC_RING"))
		{
			std::vector<OpenBabel::OBRing*>& refSSSR = pMolecule->GetSSSR();
			std::vector<OpenBabel::OBRing*>::iterator iter_rings = refSSSR.begin();
			OpenBabel::OBAtom* pAtom;

			bool bHeteroCyclic = false;

			while(iter_rings != refSSSR.end())
			{
				std::vector<int>::iterator iter_path = (*iter_rings)->_path.begin();
				while(iter_path != (*iter_rings)->_path.end())
				{
					pAtom = pMolecule->GetAtom((*iter_path));

					if(pAtom)
					{
						if(6 != pAtom->GetAtomicNum())
						{
							bHeteroCyclic = true;
							break;
						}
					}

					iter_path++;
				}

				if(bHeteroCyclic) break;

				iter_rings++;
			}
		
			ConvertBool(bHeteroCyclic, refValue);
		}
		else
		{
			// [rad] maybe it's a descriptor?
			if(SatisfyDescriptor(pMolecule, refTo, refValue))
			{
				return(true);
			}

			// [rad] unknown datatype?
			refValue = "";
			return(false);
		}

		return(true);
	}
	//--
	bool DataProperty::Satisfy(OpenBabel::OBRing* pRing, 
								const std::string& refTo, 
								std::vector<Class*>& vecSatisfiedClasses, 
								std::string& refValue)
	{
		//bool bSatisfied = false;
		int iPosition = -1;

		// [rad] if we are default, we automatically satisfy		
		if(!IsDefault())
		{			
			if(!SatisfyCommon(vecSatisfiedClasses, iPosition))
			{
				// [rad] this property does not apply

				refValue = "";
				return(false);
			}
		}

		// [rad] go through possible data types..

		if(!refTo.compare("RING_SIZE"))
		{
			ConvertInt(pRing->Size(), refValue);
		}
		else if(!refTo.compare("RING_IS_AROMATIC"))
		{
			ConvertBool(pRing->IsAromatic(), refValue);
		}
		else if(!refTo.compare("RING_IS_HOMOCYCLIC"))
		{
			OpenBabel::OBMol* pMolecule = pRing->GetParent();
			OpenBabel::OBAtom* pAtom;

			bool bHomoCyclic = true;

			std::vector<int>::iterator iter_path = pRing->_path.begin();
			while(iter_path != pRing->_path.end())
			{
				pAtom = pMolecule->GetAtom((*iter_path));

				if(pAtom)
				{
					if(6 != pAtom->GetAtomicNum())
					{
						bHomoCyclic = false;
						break;
					}
				}

				iter_path++;
			}

			ConvertBool(bHomoCyclic, refValue);
		}
		else if(!refTo.compare("RING_IS_HETEROCYCLIC"))
		{
			OpenBabel::OBMol* pMolecule = pRing->GetParent();
			OpenBabel::OBAtom* pAtom;

			bool bHeteroCyclic = false;

			std::vector<int>::iterator iter_path = pRing->_path.begin();
			while(iter_path != pRing->_path.end())
			{
				pAtom = pMolecule->GetAtom((*iter_path));

				if(pAtom)
				{
					if(6 != pAtom->GetAtomicNum())
					{
						bHeteroCyclic = true;
						break;
					}
				}

				iter_path++;
			}

			ConvertBool(bHeteroCyclic, refValue);
		}
		else
		{
			// [rad] unknown datatype?
			refValue = "";
			return(false);
		}

		return(true);
	}