Example #1
0
// Add Pattern Node
Pattern* Model::addPattern(QString patternName, int nMols, int nAtomsPerMol)
{
	Messenger::enter("Model::addPattern");
	// Determine starting atom...
	Pattern* lastp = patterns_.last();
	int start = (lastp == NULL ? 0 : lastp->startAtom() + lastp->nMolecules() * lastp->nAtoms());
	Pattern* newpnode = patterns_.add();
	newpnode->setParent(this);
	newpnode->setName(patternName);
	newpnode->initialise(patterns_.nItems()-1, start, nMols, nAtomsPerMol);
	Messenger::print("New pattern '%s' added - startatom %i, %i mols, %i atoms per mol.", qPrintable(patternName) , start+1, nMols, nAtomsPerMol);
	if ((start + nMols*nAtomsPerMol) == atoms_.nItems())
	{
		Messenger::print("Pattern description completed (spans %i atoms).", atoms_.nItems());
		energy.resize(patterns_.nItems());
		Messenger::print("Done.");
		// Patterns depend only on the properties / relation of the atoms, and not the positions..
		patternsPoint_ = log(Log::Structure);
	}
	else if ((start + nMols*nAtomsPerMol) > atoms_.nItems())
	{
		Messenger::print("New pattern '%s' extends %i atoms past number of atoms in owner model.", qPrintable(patternName), (start + nMols*nAtomsPerMol) - atoms_.nItems());
		Messenger::print("Not added.");
		patterns_.remove(newpnode);
		newpnode = NULL;
	}
	Messenger::exit("Model::addPattern");
	return newpnode;
}
Example #2
0
// Determine the locality of the supplied atom
AtomAddress Model::locateAtom(Atom* i)
{
	Messenger::enter("Model::locateAtom");
	int patternno, molno, atomno, id;
	Pattern* p;
	AtomAddress result;
	if (!createPatterns())
	{
		Messenger::print("Model::locateAtom : No valid pattern available for model.");
		Messenger::exit("Model::locateAtom");
		return result;
	}
	id = i->id();
	// First, find the pattern the atom is covered by
	patternno = -1;
	p = patterns_.first();
	while (p != NULL)
	{
		if ((id >= p->startAtom()) && (id <= p->endAtom()))
		{
			patternno = p->id();
			break;
		}
		p = p->next;
	}
	if (patternno == -1)
	{
		printf("Fatal error - could not find owner pattern for atom!\n");
		Messenger::exit("Model::locateAtom");
		return result;
	}
	// Next, find its molecule id
	id -= p->startAtom();
	molno = id / p->nAtoms();
	// Finally, get the atom offset
	atomno = id % p->nAtoms();
	// Store values, and return
	result.setPattern(p);
	result.setMolecule(molno);
	result.setOffset(atomno);
	Messenger::exit("Model::locateAtom");
	return result;
}
Example #3
0
// Own pattern
void Model::ownPattern(Pattern* source, bool own)
{
	Messenger::enter("Model::ownPattern");
	// Set the starting atom from the last pattern in the model's list
	Pattern* p = patterns_.last();
	int start = (p == NULL ? 0 : p->startAtom() + p->nMolecules() * p->nAtoms());
	// Add the pattern onto the end of the current list
	patterns_.own(source);
	energy.resize(patterns_.nItems());
	// Set startatom and endatom to be coherent with the models current list
	source->setContents(start,-1,-1);
	source->setId(patterns_.nItems()-1);
	//source->set_id(patterns_.nItems()-1);
	if (own) source->setParent(this);
	Messenger::exit("Model::ownPattern");
}