예제 #1
0
파일: matrix.cpp 프로젝트: alinelena/aten
// Set value of variable
bool MatrixVariable::set(ReturnValue& rv)
{
	if (readOnly_)
	{
		Messenger::print("A constant value (in this case a matrix) cannot be assigned to.");
		return false;
	}
	bool success = false;
	if (rv.arraySize() == -1) matrixData_ = rv.asMatrix(success);
	else if (rv.arraySize() == 9)
	{
		matrixData_.setIdentity();
		for (int n=0; n<9; ++n)
		{
			matrixData_[n/3*4+n%3] = rv.asDouble(n, success);
			if (!success) break;
		}
	}
	else if (rv.arraySize() == 16)
	{
		for (int n=0; n<16; ++n)
		{
			matrixData_[n] = rv.asDouble(n, success);
			if (!success) break;
		}
	}
	else
	{
		Messenger::print("Error: Array assigned to matrix variable must contain nine or sixteen elements.");
		success = false;
	}
	return success;
}
예제 #2
0
// Set desired value
bool ForcefieldBoundVariable::setAccessor(int i, ReturnValue& sourcerv, ReturnValue& newValue, bool hasArrayIndex, int arrayIndex)
{
	Messenger::enter("ForcefieldBoundVariable::setAccessor");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nAccessors))
	{
		printf("Internal Error: Accessor id %i is out of range for ForcefieldBound type.\n", i);
		Messenger::exit("ForcefieldBoundVariable::setAccessor");
		return false;
	}
	Accessors acc = (Accessors) i;

	// Check for correct lack/presence of array index given to original accessor, and nature of new value
	bool result = checkAccessorArrays(accessorData[acc], newValue, hasArrayIndex, arrayIndex);
	if (!result)
	{
		Messenger::exit("ForcefieldBoundVariable::setAccessor");
		return false;
	}

	// Get current data from ReturnValue
	ForcefieldBound* ptr = (ForcefieldBound*) sourcerv.asPointer(VTypes::ForcefieldBoundData, result);
	if ((!result) || (ptr == NULL))
	{
		Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::ForcefieldBoundData));
		result = false;
	}
	int n;
	if (result) switch (acc)
	{
		case (ForcefieldBoundVariable::Data):
			if ((newValue.arraySize() != -1) && (newValue.arraySize() <= MAXFFPARAMDATA)) for (n=0; n<newValue.arraySize(); ++n) ptr->setParameter(n, newValue.asDouble(n, result));
			else if (hasArrayIndex) ptr->setParameter(arrayIndex-1, newValue.asDouble());
			else for (n=0; n<MAXFFPARAMDATA; ++n) ptr->setParameter(n, newValue.asDouble());
			break;
		case (ForcefieldBoundVariable::EScale):
			if (ptr->type() != ForcefieldBound::TorsionInteraction)
			{
				Messenger::print("Tried to set the 1-4 coulombic scale factor for a non-torsion bound interaction.");
				result = false;
			}
			else ptr->setElecScale( newValue.asDouble() );
			break;
		case (ForcefieldBoundVariable::Form):
			result = ptr->setForm(newValue.asString());
			break;
		case (ForcefieldBoundVariable::TypeNames):
			if ((newValue.arraySize() != -1) && (newValue.arraySize() <= MAXFFBOUNDTYPES)) for (n=0; n<newValue.arraySize(); ++n) ptr->setTypeName(n, newValue.asString(n, result));
			else if (hasArrayIndex) ptr->setTypeName(arrayIndex-1, newValue.asString());
			else for (n=0; n<MAXFFBOUNDTYPES; ++n) ptr->setTypeName(n, newValue.asString());
			break;
		case (ForcefieldBoundVariable::VScale):
			if (ptr->type() != ForcefieldBound::TorsionInteraction)
			{
				Messenger::print("Tried to set the 1-4 coulombic scale factor for a non-torsion bound interaction.");
				result = false;
			}
			else ptr->setVdwScale( newValue.asDouble() );
			break;
		default:
			printf("ForcefieldBoundVariable::setAccessor doesn't know how to use member '%s'.\n", qPrintable(accessorData[acc].name));
			result = false;
			break;
	}
	Messenger::exit("ForcefieldBoundVariable::setAccessor");
	return result;
}