Esempio n. 1
0
bool compareMolecules(Molecule& mol1, Molecule& mol2)
{
	if(mol1.countAtoms()!=mol2.countAtoms())
		return false;
	if(mol1.countBonds()!=mol2.countBonds())
		return false;

	AtomIterator ai;
	vector<Vector3> pos1;
	vector<float> q1;
	BALL_FOREACH_ATOM(mol1, ai)
	{
		pos1.push_back(ai->getPosition());
		q1.push_back(ai->getCharge());
	}
Esempio n. 2
0
CHECK(Molecule() throw())
	b = new Molecule;
	TEST_NOT_EQUAL(b, 0)
RESULT											

CHECK(~Molecule() throw())
	delete b;
RESULT

CHECK(Molecule(const Molecule& molecule, bool deep = true) throw())
	Atom a1;
	Molecule m("a"), m2;
	m.append(a1);
	m2 = Molecule(m);
	TEST_EQUAL(m2.getName(), "a")
	TEST_EQUAL(m2.countAtoms(), 1)
RESULT

CHECK(Molecule(const String& name) throw())
	Molecule m("a");
	TEST_EQUAL(m.getName(), "a")
	Molecule m2("");
	TEST_EQUAL(m2.getName(), "")
RESULT

CHECK([EXTRA] clear())
	System s;
	Molecule m("a");
	Atom a1;
	m.append(a1);
	s.append(m);
Esempio n. 3
0
	bool KCFFile::write(const Molecule& molecule)
		throw(File::CannotWrite)
	{
		if (!isOpen() || getOpenMode() != std::ios::out)
		{
			throw File::CannotWrite(__FILE__, __LINE__, name_);
		}

		// An alias for simplicity's sake...
		std::ostream& os(getFileStream());
		
		// Write ENTRY block
		// number of blanks????  properties are not read, written??? Which ones are there?
		os << ENTRY_TAG << "      " << molecule.getName() << std::endl;
		
		static char buffer[BALL_MAX_LINE_LENGTH];

		// Write NODE block
		// How to create the KEGG atom types? How many blanks?
		// This is not specified in the KCF format description, so we use what we can
    // deduce from example files.
		// First line gets the NODE tag
		os << NODE_TAG << "      " << molecule.countAtoms() << "\n"; 
		Size count = 1;
		AtomConstIterator ai(molecule.beginAtom());
		std::map<const Atom*, Position> atom_to_index;
		for (; +ai; ++ai, ++count)
		{
			// Write the atom line.
			// Blanks????
			String type = ai->getTypeName();
			String comment;
			
			// Make sure the type is in the set of KEGG types????
			// Blanks?
			sprintf(buffer, "             %d %s %s %6.4f %6.4f %s\n", 
							count, type.c_str(), ai->getElement().getSymbol().c_str(), 
							ai->getPosition().x, ai->getPosition().y, comment.c_str());
			os << buffer;
			
			// Remember the index of the current atom to map atom
			// pointers back to indices for the EDGE section.
			atom_to_index[&*ai] = count;
		}
		
		// Write EDGE block. Walk over all bonds to do so.
		// Blanks????
		os << "EDGE    " << molecule.countBonds() << "\n";
		count = 1;
		for (ai = molecule.beginAtom(); +ai; ++ai)
		{
			for (Atom::BondConstIterator bi(ai->beginBond()); +bi; ++bi)
			{
				Position index1 = atom_to_index[bi->getFirstAtom()];
				Position index2 = atom_to_index[bi->getSecondAtom()];
				String comment;
		
				// Write every bond just once				
				if (bi->getFirstAtom() == &*ai)
				{
					sprintf(buffer, "          %4d %4d %4d %1d%s\n", 
									count, index1, index2, bi->getOrder(), comment.c_str());
					os << buffer;
					++count;
				}
			}
		}
		
		// Write the DELIMITER block
		os << DELIMITER_TAG << std::endl;
		
		return true;
	}