forge

Molecule table scripts

Convert a column containing text to a column containing a number

// Copyright (c) 2014 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Copy and convert a column containing text to a column containing
// a numerical representation:
// High -> 3
// Medium -> 2
// Low -> 2
// Any other value results in the empty string.
// The column tooltip contains the category it came from and the value is colored by category.

//Convert the "Activity Category" column to a string
var category = molecule.columnValue("Activity Category");

switch(category) {
case "High":
molecule.setColumnValue("Activity Category Value", 3);
molecule.setColumnColor("Activity Category Value", 50, 205, 50);
molecule.setColumnTooltip("Activity Category Value", category);
break;
case "Medium":
molecule.setColumnValue("Activity Category Value", 2);
molecule.setColumnColor("Activity Category Value", 255, 215, 0);
molecule.setColumnTooltip("Activity Category Value", category);
break;
case "Low":
molecule.setColumnValue("Activity Category Value", 1);
molecule.setColumnColor("Activity Category Value", 244, 0, 0);
molecule.setColumnTooltip("Activity Category Value", category);
break;
}

Count the number of sp3 Carbon atoms in each molecule

// Copyright (c) 2014 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Count the number of CSP3 atoms in the molecule and
// displays it in the "Csp3 Count" column.

var csp3AtomsCount = 0;
for (var i = 0; i < molecule.atoms.length; i++) {
if (molecule.atoms[i].atomicNumber == 6 && molecule.atoms[i].isSp3()) {
csp3AtomsCount += 1;
}
}

// Set the value in the "Csp3 Count" column to csp3AtomsCount
molecule.setColumnValue("Csp3 Count", csp3AtomsCount);

Create a ‘Flexibility factor’ for all molecules

// Copyright (c) 2014 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Calculate the flexibility factor of the the molecule and
// displays it in the "Flexibility Factor" column. If the "Flexibility Factor"
// is greater than 1.5 then display the text in red. "Flexibility Factor" is
// defined as (Number of single bonds)/(number of heave atoms).

// Count the number of single bonds
var singleBondsCount = 0;

for (var i = 0; i<molecule.bonds.length; i++) {
if (molecule.bonds[i].multipleBondCount === 1) {
singleBondsCount += 1;
}
}

// Convert the heavy atom count in the "#Atoms" column to int
var heavyAtomCount = parseInt(molecule.columnValue("#Atoms"));
var flexibilityFactor = singleBondsCount / heavyAtomCount;

// Convert a flexibilityFactor into a string, keeping only 3 decimals
flexibilityFactor = flexibilityFactor.toFixed(3);

// Set the value in the "Flexibility Factor" column to flexibilityFactor
molecule.setColumnValue("Flexibility Factor", flexibilityFactor);

// Set the column text color to red if the Flexibility Factor is over 1.5
// otherwise the the default, black.
if (flexibilityFactor > 1.5) {
molecule.setColumnColor("Flexibility Factor", 255, 0, 0);
}

Format the activity values in a column

// Copyright (c) 2014 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Copy the "pIC50" column to the "Formatted pIC50" column.
// If the "pIC50" is missing, invalid or negative then the "Formatted pIC50"
// column will contain 0.0.

// Convert the heavy atom count in the "pIC50" column to float
// If the molecule does not have a value or the value is not a float then
// activity is set to NaN.
var activity = parseFloat(molecule.columnValue("pIC50"));

if (isNaN(activity) || activity <= 0.0) {
activity = 0.0;
}
// Set the value in the "Formatted pIC50" column to activity
molecule.setColumnValue("Formatted pIC50", activity);

Find the largest absolute field point

// Copyright (c) 2014 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Find the largest negative or positiv field point and
// displays it in the "Largest Field Point" column. If the largest field point
// is negative then color the value blue, if its positive then color the value red.
// If there are no field points then the value will be 0.0 and color black.

// Find the largest field point
var largestFieldPoint = 0;

// The atoms array also contains the field points
for (var i=0;i<molecule.atoms.length;i++) {
if (molecule.atoms[i].isPosField() || molecule.atoms[i].isNegField()) {

// The field point size is stored in the charge properties
if (Math.abs(molecule.atoms[i].charge) > Math.abs(largestFieldPoint)) {
largestFieldPoint = molecule.atoms[i].charge;
}
}
}

// Convert a largestFieldPoint into a string, keeping only 2 decimals
largestFieldPoint = largestFieldPoint.toFixed(2);
// Set the value in the "Largest Field Point" column to absolute value for largestFieldPoint
molecule.setColumnValue("Largest Field Point", Math.abs(largestFieldPoint));

if (largestFieldPoint > 0) {
// Color negative field points blue
molecule.setColumnColor("Largest Field Point", 51, 217, 230);
} else if (largestFieldPoint < 0) {
// Color positive field points blue
molecule.setColumnColor("Largest Field Point", 179, 64, 64);
}
// Otherwise keep the default color, black.

LipE over heavy atom count

// Copyright (c) 2014 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Calculate the LipE divided by the heavy atom count.
// The result is displayed it in the "LipE/#Atoms" column.

// Convert the LipE in the "LipE (Primary)" column to float
var lipE = parseFloat(molecule.columnValue("LipE (Primary)"));

// Convert the heavy atom count in the "#Atoms" column to int
var heavyAtomCount = parseInt(molecule.columnValue("#Atoms"));

var result = lipE / heavyAtomCount;

// Convert a result into a string, keeping only 3 decimals
result = result.toFixed(3);

// Set the value in the "LipE/#Atoms" column to result
molecule.setColumnValue("LipE/#Atoms", result);

Nitrogen count

// Copyright (c) 2014 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Count the number of nitrogen atoms in the molecule and
// displays it in the "#Nitrogens" column.

var nitrogensCount = 0;

for (var i = 0; i<molecule.atoms.length; i++) {
if (molecule.atoms[i].atomicNumber === 7) {
nitrogensCount += 1;
}
}
// Set the value in the "#Nitrogens" column to result
molecule.setColumnValue("#Nitrogens", nitrogensCount);

nM Activity Selectivity

// Copyright (c) 2014 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Calculate the selectivity of 2 activity columns where their units are in nM.
// The result is displayed it in the "Activity Log Selectivity" column.
// The column has a custom tooltip which displays the log 10 of both the activity values.

//Function to calculates log with base 10 of val
function log10(val) {
return Math.log(val) / Math.LN10;
}

//Convert the activities to floats
var activity1 = parseFloat(molecule.columnValue("Activity1Column"));
var activity2 = parseFloat(molecule.columnValue("Activity2Column"));

//Calculate the log10 of the activity data
var activity1Log = log10(activity1);
var activity2Log = log10(activity2);

//Calculate the selectivity
var selectivity = activity1Log - activity2Log;

//Convert a selectivity into a string, keeping only 3 decimals
selectivity = selectivity.toFixed(3);

//Insert the ratio into the Activity Log Ratio column
molecule.setColumnValue("Activity Log Selectivity", selectivity);
molecule.setColumnTooltip("Activity Log Selectivity", activity1Log + " - " + activity2Log);

Remove inequality signs

// Copyright (c) 2014 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Copy the "ActivityColumn" column to the "Formatted Activity" column.
// If the "ActivityColumn" contains ">", ">=", "<" or "<=" signs then the signs are removed
// leaving the raw activity value.
// Convert the activity in the "ActivityColumn" column to a string and a float

var activity = String(molecule.columnValue("ActivityColumn"));
var activityFloat = parseFloat(activity);
if (isNaN(activityFloat)) {
// The activity column does not contain a float
// Replace any inequality signs with the empty string
activity = activity.replace(/>=?|<=?/g, "").trim();
}

//Try to parse the activity again. If it is successfully then put in in the Formatted Activity column
activityFloat = parseFloat(activity);
if (!isNaN(activityFloat)) {
molecule.setColumnValue("Formatted Activity", activityFloat);
}

Function to return the log10 of a number

// Copyright (c) 2015 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Function to calculates log with base 10 of val

function log10(val) {
return Math.log(val) / Math.LN10;
}

Convert % inhibition to activity category

// Copyright (c) 2016 Cresset BioMolecular Discovery Ltd.
//
// Released to the public domain.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Description: Convert the "PercentageActivity" column to an "Activity
// Category Value" column. Molecules with % inhibition < 30 are in
// category "1" (red), molecules with 30 <= % inhibition < 70 are in
// category "2" (yellow) and molecules with % inhibition >= 70 are in
// category "3" (green).
// If the "PercentageActivity" column contains ">", ">=", "<", "<=" or "%" signs
// then the signs are removed leaving the raw activity value.

var activity = String(molecule.columnValue("PercentageActivity"));
var activityFloat = parseFloat(activity);
if (isNaN(activityFloat)) {
// The activity column does not contain a float
// Replace any inequality signs with the empty string, then do the same with %
activity = activity.replace(/>=?|<=?/g, "").replace(/%/g, "").trim();
}

//Try to parse the activity again. If it is successful then put in
// the Activity Category Value
activityFloat = parseFloat(activity);
if (!isNaN(activityFloat)) {
if (activityFloat >= 70) {
category = "% activity >= 70";
molecule.setColumnValue("Activity Category Value", 3);
molecule.setColumnColor("Activity Category Value", 50, 205, 50);
}
if (!(activityFloat < 30) && !(activityFloat >= 70)) {
category = "30 <= % activity < 70";
molecule.setColumnValue("Activity Category Value", 2);
molecule.setColumnColor("Activity Category Value", 255, 215, 0);
}
if (activityFloat < 30) {
category = "% activity < 30";
molecule.setColumnValue("Activity Category Value", 1);
molecule.setColumnColor("Activity Category Value", 244, 0, 0);
}
molecule.setColumnTooltip("Activity Category Value", category);
}

Try Cresset solutions on your project

Request a free software evaluation