package edu.sdsc.mbt.util; import edu.sdsc.mbt.util.PeriodicTable; import edu.sdsc.mbt.*; import edu.sdsc.sirius.util.VectorSet; public class ElementProperties { /** * TODO there should be a clear difference between figures for atomic, ionic, covalent * and Van der Walls radii of individual elements */ private static float elementColors[][]; private static double atomRadii[]; private static double ionRadii[]; private static int elementValencies[][]; private static int elementCount = 0; private static double[][] bondLengths; private static int geometryReference[]; public static final int LINEAR = 0; public static final int TRIGONAL = 1; public static final int TETRAHEDRAL = 2; public static final int TRIGONAL_BIPYRAMIDAL = 3; public static final int OCTAHEDRAL = 4; private static int[] defaultValency = new int[]{ 1 }; private static VectorSet bondGeometries[] = new VectorSet[5];//a reference table of different geometries numbered by integers static { elementCount = PeriodicTable.getElementCount( ); elementValencies = new int[elementCount][];//since each element may have a set of possible valencies elementColors = new float[elementCount][3]; atomRadii = new double[elementCount]; ionRadii = new double[elementCount]; geometryReference = new int[elementCount];//values are indices of geometry types // Initially set element colors to a medium gray for ( int i=0; i 1.0f ) r = 1.0f; if ( g < 0.0f ) g = 0.0f; if ( g > 1.0f ) g = 1.0f; if ( b < 0.0f ) b = 0.0f; if ( b > 1.0f ) b = 1.0f; elementColors[number][0] = r; elementColors[number][1] = g; elementColors[number][2] = b; } /** * Set the RGB color of the given element name. * Color components are clamped between 0.0 and 1.0. */ public static void setElementColor( String name, float r, float g, float b ) { setElementColor( PeriodicTable.getElementNumber(name), r, g, b ); } /** * Get the RGB color of the given element number. * Color components are clamped between 0.0 and 1.0. */ public static float[] getElementColor( int number ) { if ( number < 0 ) return null; if ( number >= elementColors.length ) return null; return elementColors[number]; } /** * Get the RGB color of the given element name. * Color components are clamped between 0.0 and 1.0. */ public static float[] getElementColor( String name ) { int number = PeriodicTable.getElementNumber( name ); if ( number < 0 ) return null; if ( number >= elementColors.length ) return null; return elementColors[ number ]; } // // Radius methods // /** * Set the radius of the given element number. * Radius values are constrained to be non-negative. */ public static void setAtomRadius( int number, double radius ) { if ( radius < 0.0 ) radius = 0.0; atomRadii[number] = radius; } /** * Set the radius of the given element name. * Radius values are constrained to be non-negative. */ public static void setAtomRadius( String name, double radius ) { setAtomRadius( PeriodicTable.getElementNumber(name), radius ); } /** * Get the radius of the given element number. * Radius values are constrained to be non-negative. */ public static double getAtomRadius( int number ){ if (number < 0 || number > atomRadii.length-1) return 1.0; return atomRadii[number]; } public static double getIonRadius( int number ){ return ionRadii[number]; } public static void setIonRadius( String name, double radius ) { setIonRadius( PeriodicTable.getElementNumber(name), radius ); } public static void setIonRadius( int number, double radius ) { if ( radius < 0.0 ) radius = 0.0; ionRadii[number] = radius; } /** * Get the radius of the given element name. * Radius values are constrained to be non-negative. */ public static double getAtomRadius( String name ) { return atomRadii[ PeriodicTable.getElementNumber(name) ]; } public static double getAtomRadius(short index){ return atomRadii[index]; } /** * Sets element colors to their default values * */ public static void setDefaultElementColors(){ // Initially set element colors to a medium gray for ( int i=0; i= elementValencies.length) return defaultValency; return elementValencies[(int)index]; } public static VectorSet getBondGeometry(Atom atom){ if (atom.hybridization != Atom.SP3){ /** * TODO a dirty hack to correctly handle phosphates in nucleic acids. * Will need a more general mechanism for dealing with geometries around * different elements in various hybridization states... */ if (atom.element == 15)return bondGeometries[TETRAHEDRAL].copy(); if (atom.hybridization == Atom.SP2){ return bondGeometries[TRIGONAL].copy(); } else if (atom.hybridization == Atom.SP){ return bondGeometries[LINEAR].copy(); } return bondGeometries[TETRAHEDRAL].copy(); } else{ int index = geometryReference[ (int)atom.element ]; if (index < LINEAR && index > OCTAHEDRAL) return bondGeometries[TETRAHEDRAL].copy(); return bondGeometries[index].copy(); } } }