Exemplo n.º 1
0
// Retrieve desired value
bool BasisShellVariable::retrieveAccessor(int i, ReturnValue& rv, bool hasArrayIndex, int arrayIndex)
{
	Messenger::enter("BasisShellVariable::retrieveAccessor");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nAccessors))
	{
		printf("Internal Error: Accessor id %i is out of range for BasisShell type.\n", i);
		Messenger::exit("BasisShellVariable::retrieveAccessor");
		return false;
	}
	Accessors acc = (Accessors) i;
	// Check for correct lack/presence of array index given
	if ((accessorData[i].arraySize == 0) && hasArrayIndex)
	{
		Messenger::print("Error: Unnecessary array index provided for member '%s'.", qPrintable(accessorData[i].name));
		Messenger::exit("BasisShellVariable::retrieveAccessor");
		return false;
	}
	else if ((accessorData[i].arraySize > 0) && (hasArrayIndex))
	{
		if ((arrayIndex < 1) || (arrayIndex > accessorData[i].arraySize))
		{
			Messenger::print("Error: Array index out of bounds for member '%s' (%i, range is 1-%i).", qPrintable(accessorData[i].name), arrayIndex, accessorData[i].arraySize);
			Messenger::exit("BasisShellVariable::retrieveAccessor");
			return false;
		}
	}
	// Get current data from ReturnValue
	bool result = true;
	BasisShell* ptr = (BasisShell*) rv.asPointer(VTypes::BasisShellData, result);
	if ((!result) || (ptr == NULL))
	{
		Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::BasisShellData));
		result = false;
	}
	if (result) switch (acc)
	{
		case (BasisShellVariable::AtomId):
			rv.set(ptr->atomId()+1);
			break;
		case (BasisShellVariable::Primitives):
			if ((arrayIndex < 1) || (arrayIndex > ptr->nPrimitives()))
			{
				Messenger::print("Array index [%i] is out of range for 'primitives' member.", arrayIndex);
				result = false;
			}
			else rv.set(VTypes::BasisPrimitiveData, ptr->primitive(arrayIndex-1));
			break;
		case (BasisShellVariable::Type):
			rv.set(BasisShell::basisShellType(ptr->type()));
			break;
		default:
			printf("Internal Error: Access to member '%s' has not been defined in BasisShellVariable.\n", qPrintable(accessorData[i].name));
			result = false;
			break;
	}
	Messenger::exit("BasisShellVariable::retrieveAccessor");
	return result;
}
Exemplo n.º 2
0
ATEN_USING_NAMESPACE

// Get part of string before specified character/string
bool Commands::function_AfterStr(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	rv.set(c->argc(0).section(c->argc(1), 1));	// ATEN2 TODO Test this
	if (c->hasArg(2) && c->argb(2) && (rv.asString()[0] == '\0')) rv.set(c->argc(0));
	return true;
}
Exemplo n.º 3
0
// Retrieve desired value
bool WidgetVariable::retrieveAccessor(int i, ReturnValue& rv, bool hasArrayIndex, int arrayIndex)
{
	Messenger::enter("WidgetVariable::retrieveAccessor");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nAccessors))
	{
		printf("Internal Error: Accessor id %i is out of range for Aten type.\n", i);
		Messenger::exit("WidgetVariable::retrieveAccessor");
		return false;
	}
	Accessors acc = (Accessors) i;
	// Check for correct lack/presence of array index given
	if ((accessorData[i].arraySize == 0) && hasArrayIndex)
	{
		Messenger::print("Error: Unnecessary array index provided for member '%s'.", qPrintable(accessorData[i].name));
		Messenger::exit("WidgetVariable::retrieveAccessor");
		return false;
	}
	else if ((accessorData[i].arraySize > 0) && (hasArrayIndex))
	{
		if ((arrayIndex < 1) || (arrayIndex > accessorData[i].arraySize))
		{
			Messenger::print("Error: Array index out of bounds for member '%s' (%i, range is 1-%i).", qPrintable(accessorData[i].name), arrayIndex, accessorData[i].arraySize);
			Messenger::exit("WidgetVariable::retrieveAccessor");
			return false;
		}
	}
	// Variables used in retrieval
	bool result = true;
	TreeGuiWidget* ptr = (TreeGuiWidget*) rv.asPointer(VTypes::WidgetData, result);
	if ((!result) || (ptr == NULL))
	{
	        Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::WidgetData));
	        result = false;
	}
	if (result) switch (acc)
	{
		case (WidgetVariable::Enabled):
			rv.set(ptr->enabled());
			break;
		case (WidgetVariable::VerticalFill):
			rv.set(ptr->qtWidgetObject() == NULL ? false : ptr->qtWidgetObject()->autoFillVertical());
			break;
		case (WidgetVariable::Visible):
			rv.set(ptr->visible());
			break;
		default:
			printf("Internal Error: Access to member '%s' has not been defined in WidgetVariable.\n", qPrintable(accessorData[i].name));
			result = false;
			break;
	}
	Messenger::exit("WidgetVariable::retrieveAccessor");
	return result;
}
Exemplo n.º 4
0
// Retrieve desired value
bool MatrixVariable::retrieveAccessor(int i, ReturnValue& rv, bool hasArrayIndex, int arrayIndex)
{
	Messenger::enter("MatrixVariable::retrieveAccessor");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nAccessors))
	{
		printf("Internal Error: Accessor id %i is out of range for Matrix type.\n", i);
		Messenger::exit("MatrixVariable::retrieveAccessor");
		return false;
	}
	Accessors acc = (Accessors) i;
	// Check for correct lack/presence of array index given
	if (hasArrayIndex)
	{
		Messenger::print("Error: Unnecessary array index provided for member '%s'.", qPrintable(accessorData[i].name));
		Messenger::exit("MatrixVariable::retrieveAccessor");
		return false;
	}
	// Get current data from ReturnValue
	bool result = true;
	Matrix m = rv.asMatrix(result);
	if (result) switch (acc)
	{
		case (MatrixVariable::Determinant):
			rv.set(m.determinant());
			break;
		case (MatrixVariable::XX):
		case (MatrixVariable::XY):
		case (MatrixVariable::XZ):
		case (MatrixVariable::XW):
		case (MatrixVariable::YX):
		case (MatrixVariable::YY):
		case (MatrixVariable::YZ):
		case (MatrixVariable::YW):
		case (MatrixVariable::ZX):
		case (MatrixVariable::ZY):
		case (MatrixVariable::ZZ):
		case (MatrixVariable::ZW):
		case (MatrixVariable::WX):
		case (MatrixVariable::WY):
		case (MatrixVariable::WZ):
		case (MatrixVariable::WW):
			rv.set(m[acc-MatrixVariable::XX]);
			break;
		default:
			printf("Internal Error: Access to member '%s' has not been defined in MatrixVariable.\n", qPrintable(accessorData[i].name));
			result = false;
			break;
	}
	Messenger::exit("MatrixVariable::retrieveAccessor");
	return result;
}
Exemplo n.º 5
0
// Perform desired function
bool ForcefieldBoundVariable::performFunction(int i, ReturnValue& rv, TreeNode* node)
{
	Messenger::enter("ForcefieldBoundVariable::performFunction");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nFunctions))
	{
		printf("Internal Error: FunctionAccessor id %i is out of range for ForcefieldBound type.\n", i);
		Messenger::exit("ForcefieldBoundVariable::performFunction");
		return false;
	}

	// Get current data from ReturnValue
	bool result = true;
	ForcefieldBound* ptr = (ForcefieldBound*) rv.asPointer(VTypes::ForcefieldBoundData, result);
	int id;
	if (result) switch (i)
	{
		case (ForcefieldBoundVariable::Parameter):
			switch (ptr->type())
			{
				case (ForcefieldBound::BondInteraction):
				case (ForcefieldBound::UreyBradleyInteraction):
					id = BondFunctions::bondParameter(ptr->bondForm(), node->argc(0), true);
					if (id == BondFunctions::functionData[ptr->bondForm()].nParameters) result = false;
					else rv.set(ptr->parameter(id));
					break;
				case (ForcefieldBound::AngleInteraction):
					id = AngleFunctions::angleParameter(ptr->angleForm(), node->argc(0), true);
					if (id == AngleFunctions::functionData[ptr->angleForm()].nParameters) result = false;
					else rv.set(ptr->parameter(id));
					break;
				case (ForcefieldBound::TorsionInteraction):
				case (ForcefieldBound::ImproperInteraction):
					id = TorsionFunctions::torsionParameter(ptr->torsionForm(), node->argc(0), true);
					if (id == TorsionFunctions::functionData[ptr->torsionForm()].nParameters) result = false;
					else rv.set(ptr->parameter(id));
					break;
        default:
          break;  
			}
			break;
		default:
			printf("Internal Error: Access to function '%s' has not been defined in ForcefieldBoundVariable.\n", qPrintable(functionData[i].name));
			result = false;
			break;
	}
	Messenger::exit("ForcefieldBoundVariable::performFunction");
	return result;
}
Exemplo n.º 6
0
void List<T>::splice(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
    validate_argument_count_at_least(argc, 1);

    auto list = get_internal<T, ListClass<T>>(this_object);
    size_t size = list->size();
    long index = std::min<long>(Value::to_number(ctx, arguments[0]), size);
    if (index < 0) {
        index = std::max<long>(size + index, 0);
    }

    size_t remove;
    if (argc < 2) {
        remove = size - index;
    }
    else {
        remove = std::max<long>(Value::to_number(ctx, arguments[1]), 0);
        remove = std::min<long>(remove, size - index);
    }
    
    std::vector<ValueType> removed_objects;
    removed_objects.reserve(remove);

    for (size_t i = 0; i < remove; i++) {
        auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(index));

        removed_objects.push_back(RealmObject<T>::create_instance(ctx, realm_object));
        list->remove(index);
    }
    for (size_t i = 2; i < argc; i++) {
        list->insert(ctx, arguments[i], index + i - 2);
    }

    return_value.set(Object::create_array(ctx, removed_objects));
}
Exemplo n.º 7
0
// Set whether 2D grid uses data value as height component
bool Commands::function_GridUseZ(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::GridPointer)) return false;
	if (c->hasArg(0)) obj.g->setUseDataForZ(c->argb(0));
	rv.set(obj.g->useDataForZ());
	return true;
}
Exemplo n.º 8
0
// Replace characters in supplied string
bool Commands::function_ReplaceChars(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	QString result = c->argc(0);
	for (int n=0; n<c->argc(1).length(); ++n) result = result.replace(c->argc(1).at(n), c->argc(2));
	rv.set(result);
	return true;
}
Exemplo n.º 9
0
// Perform desired function
bool BasisShellVariable::performFunction(int i, ReturnValue& rv, TreeNode* node)
{
	Messenger::enter("BasisShellVariable::performFunction");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nFunctions))
	{
		printf("Internal Error: FunctionAccessor id %i is out of range for BasisShell type.\n", i);
		Messenger::exit("BasisShellVariable::performFunction");
		return false;
	}
	// Get current data from ReturnValue
	bool result = true;
	BasisShell* ptr = (BasisShell*) rv.asPointer(VTypes::BasisShellData, result);
	BasisPrimitive* prim;
	int n;
	if (result) switch (i)
	{
		case (BasisShellVariable::AddPrimitive):
			prim = ptr->addPrimitive();
			prim->setExponent( node->argd(0) );
			for (n=1; n<node->nArgs(); ++n) prim->addCoefficient(node->argd(n));
			rv.set(VTypes::BasisPrimitiveData, prim);
			break;
		default:
			printf("Internal Error: Access to function '%s' has not been defined in BasisShellVariable.\n", qPrintable(functionData[i].name));
			result = false;
			break;
	}
	Messenger::exit("BasisShellVariable::performFunction");
	return result;
}
Exemplo n.º 10
0
// Set view percentage for secondary surface
bool Commands::function_GridViewPercentageSecondary(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::GridPointer)) return false;
	if (c->hasArg(0)) obj.g->setSecondaryCutoffAsViewPercentage(c->argd(0), c->hasArg(1) ? c->argb(1) : false);
	rv.set((obj.g->partialSecondarySum() / obj.g->totalAbsoluteSum())*100.0);
	return true;
}
Exemplo n.º 11
0
// Set visibility of grid data
bool Commands::function_GridVisible(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::GridPointer)) return false;
	if (c->hasArg(0)) obj.g->setVisible(c->argb(0));
	rv.set(obj.g->isVisible());
	return true;
}
Exemplo n.º 12
0
// Return value of node
bool MatrixVariable::execute(ReturnValue& rv)
{
	// If this matrix is a constant, read the nine stored expressions to recreate it
	if (readOnly_) reCreate();
	rv.set(matrixData_);
	return true;
}
Exemplo n.º 13
0
// Perform desired function
bool BondVariable::performFunction(int i, ReturnValue& rv, TreeNode* node)
{
	Messenger::enter("BondVariable::performFunction");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nFunctions))
	{
		printf("Internal Error: FunctionAccessor id %i is out of range for Bond type.\n", i);
		Messenger::exit("BondVariable::performFunction");
		return false;
	}
	// Get current data from ReturnValue
	bool result = true;
	Bond* ptr = (Bond*) rv.asPointer(VTypes::BondData, result);
	if (result) switch (i)
	{
		case (BondVariable::Partner):
			rv.set(VTypes::AtomData, ptr->partner( (Atom*) node->argp(0, VTypes::AtomData)));
			break;
		default:
			printf("Internal Error: Access to function '%s' has not been defined in BondVariable.\n", qPrintable(functionData[i].name));
			result = false;
			break;
	}
	Messenger::exit("BondVariable::performFunction");
	return result;
}
Exemplo n.º 14
0
// Initialise grid, setting extent of grid (number of points in each direction)
bool Commands::function_InitialiseGrid(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::GridPointer)) return false;
	Grid::GridType gt = Grid::gridType(c->argc(0), true);
	if (gt == Grid::nGridTypes) return false;
	rv.set(obj.g->initialise(gt, c->arg3i(1)));
	return true;
}
Exemplo n.º 15
0
// Create new grid in the current model
bool Commands::function_NewGrid(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::ModelPointer)) return false;
	obj.g = aten_.currentModel()->addGrid();
	obj.g->setName(c->argc(0).trimmed());
	rv.set(VTypes::GridData, obj.g);
	return true;
}
Exemplo n.º 16
0
void RealmObjectClass<T>::get_property(ContextType ctx, ObjectType object, const String &property, ReturnValue &return_value) {
    try {
        auto realm_object = get_internal<T, RealmObjectClass<T>>(object);
        auto result = realm_object->template get_property_value<ValueType>(ctx, property);
        return_value.set(result);
    } catch (InvalidPropertyException &ex) {
        // getters for nonexistent properties in JS should always return undefined
    }
}
Exemplo n.º 17
0
void List<T>::unshift(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
    validate_argument_count_at_least(argc, 1);

    auto list = get_internal<T, ListClass<T>>(this_object);
    for (size_t i = 0; i < argc; i++) {
        list->insert(ctx, arguments[i], i);
    }

    return_value.set((uint32_t)list->size());
}
Exemplo n.º 18
0
// Return value of node as array
bool MatrixArrayVariable::executeAsArray(ReturnValue& rv, int arrayIndex)
{
	// Check bounds
	if ((arrayIndex < 0) || (arrayIndex >= arraySize_))
	{
		Messenger::print("Error: Array index %i is out of bounds for array '%s'.", arrayIndex+1, qPrintable(name_));
		return false;
	}
	rv.set( matrixArrayData_[arrayIndex] );
	return true;
}
Exemplo n.º 19
0
void ListClass<T>::unshift(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
    validate_argument_count_at_least(argc, 1);

    auto list = get_internal<T, ListClass<T>>(this_object);
    NativeAccessor<T> accessor(ctx, list->get_realm(), list->get_object_schema());
    for (size_t i = 0; i < argc; i++) {
        list->insert(accessor, i, arguments[i]);
    }

    return_value.set((uint32_t)list->size());
}
Exemplo n.º 20
0
// Load grid ('loadgrid <filename>')
bool Commands::function_LoadGrid(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::ModelPointer)) return false;
	Grid* g = NULL;

	if (aten_.importGrid(obj.rs(), c->argc(0))) g = obj.g;
	else return false;

	// Set return value
	rv.set(VTypes::GridData, g);
	return true;
}
Exemplo n.º 21
0
// Convert string to integer number
bool Commands::function_AToI(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	static QRegularExpression re("[\\d.\\-eE]+");
	QRegularExpressionMatch match = re.match(c->argc(0));
	if (match.hasMatch()) rv.set( match.captured(0).toInt() );
	else
	{
		Messenger::warn("Couldn't convert '%s' to an integer number.\n", qPrintable(c->argc(0)));
		rv.reset();
	}
	return true;
}
Exemplo n.º 22
0
// Return string based on supplied format and arguments
bool Commands::function_ToA(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	Format* fmt = c->createFormat(0,1);
	if (fmt == NULL)
	{
		printf("Error - No format defined in 'toa' command.\n");
		return false;
	}
	bool result = fmt->writeToString();
	if (result) rv.set(fmt->string());
	else rv.reset();
	return result;
}
Exemplo n.º 23
0
void List<T>::shift(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
    validate_argument_count(argc, 0);

    auto list = get_internal<T, ListClass<T>>(this_object);
    if (list->size() == 0) {
        list->verify_in_transaction();
        return_value.set_undefined();
    }
    else {
        auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(0));

        return_value.set(RealmObject<T>::create_instance(ctx, realm_object));
        list->remove(0);
    }
}
Exemplo n.º 24
0
void ListClass<T>::pop(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
    validate_argument_count(argc, 0);

    auto list = get_internal<T, ListClass<T>>(this_object);
    size_t size = list->size();
    if (size == 0) {
        list->verify_in_transaction();
        return_value.set_undefined();
    }
    else {
        size_t index = size - 1;
        auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(index));

        return_value.set(RealmObjectClass<T>::create_instance(ctx, std::move(realm_object)));
        list->remove(index);
    }
}
Exemplo n.º 25
0
// Return nth grid of model
bool Commands::function_GetGrid(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::ModelPointer)) return false;
	Grid* g = NULL;
	switch (c->argType(0))
	{
		case (VTypes::IntegerData):
			g = obj.rs()->grid(c->argi(0)-1);
			break;
		case (VTypes::GridData):
			g = (Grid*) c->argp(0, VTypes::GridData);
			break;
		default:
			Messenger::print("Can't convert a variable of type '%s' to a Grid.", VTypes::dataType(c->argType(0)));
			break;
	}
	if (g == NULL) return false;
	rv.set(VTypes::GridData, g);
	return true;
}
Exemplo n.º 26
0
ATEN_USING_NAMESPACE

// Assign charge to selected atoms in model ('charge <q>'), or get charge of current selection
bool Commands::function_Charge(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::ModelPointer)) return false;
	double q = 0.0;
	if (c->hasArg(0))
	{
		obj.rs()->beginUndoState("Charge selected atoms");
		for (RefListItem<Atom,int>* ri = obj.rs()->selection(); ri != NULL; ri = ri->next) obj.rs()->atomSetCharge(ri->item, c->argd(0));
		obj.rs()->endUndoState();
	}
	else
	{
		q = 0.0;
		for (RefListItem<Atom,int>* ri = obj.rs()->selection(); ri != NULL; ri = ri->next) q += ri->item->charge();
	}
	rv.set(q);
	return true;
}
Exemplo n.º 27
0
void List<T>::get_index(ContextType ctx, ObjectType object, uint32_t index, ReturnValue &return_value) {
    auto list = get_internal<T, ListClass<T>>(object);
    auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(index));

    return_value.set(RealmObject<T>::create_instance(ctx, realm_object));
}
Exemplo n.º 28
0
void List<T>::get_length(ContextType ctx, ObjectType object, ReturnValue &return_value) {
    auto list = get_internal<T, ListClass<T>>(object);
    return_value.set((uint32_t)list->size());
}
Exemplo n.º 29
0
void List<T>::sorted(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
    validate_argument_count(argc, 1, 2);

    auto list = get_internal<T, ListClass<T>>(this_object);
    return_value.set(Results<T>::create_sorted(ctx, *list, argc, arguments));
}
Exemplo n.º 30
0
void List<T>::snapshot(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
    validate_argument_count(argc, 0);

    auto list = get_internal<T, ListClass<T>>(this_object);
    return_value.set(Results<T>::create_instance(ctx, *list, false));
}