Skip to content

Commit

Permalink
stringProperties experimentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Aug 13, 2022
1 parent e7d3cd9 commit da82c96
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 263 deletions.
30 changes: 11 additions & 19 deletions js/common/model/ElectronGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,48 @@ import EnumerationDeprecated from '../../../../phet-core/js/EnumerationDeprecate
import moleculeShapes from '../../moleculeShapes.js';
import moleculeShapesStrings from '../../moleculeShapesStrings.js';

const geometryDiatomicString = moleculeShapesStrings.geometry.diatomic;
const geometryEmptyString = moleculeShapesStrings.geometry.empty;
const geometryLinearString = moleculeShapesStrings.geometry.linear;
const geometryOctahedralString = moleculeShapesStrings.geometry.octahedral;
const geometryTetrahedralString = moleculeShapesStrings.geometry.tetrahedral;
const geometryTrigonalBipyramidalString = moleculeShapesStrings.geometry.trigonalBipyramidal;
const geometryTrigonalPlanarString = moleculeShapesStrings.geometry.trigonalPlanar;

// Constant for the tetrahedral shape
const TETRA_CONST = Math.PI * -19.471220333 / 180;

class ElectronGeometryValue {
/*
* @param {string} string
* @param {IProperty<string>} stringProperty
* @param {Array.<Vector3>} unitVectors - Ordered list of orientations taken by an ideal configuration
*/
constructor( string, unitVectors ) {
// @public {string}
this.string = string;
constructor( stringProperty, unitVectors ) {
// @public {IProperty<string>}
this.stringProperty = stringProperty;

// @public {Array.<Vector3>}
this.unitVectors = unitVectors;
}
}

const ElectronGeometry = EnumerationDeprecated.byMap( {
EMPTY: new ElectronGeometryValue( geometryEmptyString, [] ),
EMPTY: new ElectronGeometryValue( moleculeShapesStrings.geometry.emptyProperty, [] ),
DIATOMIC: new ElectronGeometryValue(
geometryDiatomicString,
moleculeShapesStrings.geometry.diatomicProperty,
[
new Vector3( 1, 0, 0 )
]
),
LINEAR: new ElectronGeometryValue(
geometryLinearString,
moleculeShapesStrings.geometry.linearProperty,
[
new Vector3( 1, 0, 0 ),
new Vector3( -1, 0, 0 )
]
),
TRIGONAL_PLANAR: new ElectronGeometryValue(
geometryTrigonalPlanarString,
moleculeShapesStrings.geometry.trigonalPlanarProperty,
[
new Vector3( 1, 0, 0 ),
new Vector3( Math.cos( Math.PI * 2 / 3 ), Math.sin( Math.PI * 2 / 3 ), 0 ),
new Vector3( Math.cos( Math.PI * 4 / 3 ), Math.sin( Math.PI * 4 / 3 ), 0 )
]
),
TETRAHEDRAL: new ElectronGeometryValue(
geometryTetrahedralString,
moleculeShapesStrings.geometry.tetrahedralProperty,
[
new Vector3( 0, 0, 1 ),
new Vector3( Math.cos( 0 ) * Math.cos( TETRA_CONST ), Math.sin( 0 ) * Math.cos( TETRA_CONST ), Math.sin( TETRA_CONST ) ),
Expand All @@ -71,7 +63,7 @@ const ElectronGeometry = EnumerationDeprecated.byMap( {
]
),
TRIGONAL_BIPYRAMIDAL: new ElectronGeometryValue(
geometryTrigonalBipyramidalString,
moleculeShapesStrings.geometry.trigonalBipyramidalProperty,
[
// equitorial (fills up with lone pairs first)
new Vector3( 0, 1, 0 ),
Expand All @@ -84,7 +76,7 @@ const ElectronGeometry = EnumerationDeprecated.byMap( {
]
),
OCTAHEDRAL: new ElectronGeometryValue(
geometryOctahedralString,
moleculeShapesStrings.geometry.octahedralProperty,
[
// opposites first
new Vector3( 0, 0, 1 ),
Expand Down
48 changes: 17 additions & 31 deletions js/common/model/MoleculeGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,34 @@ import EnumerationDeprecated from '../../../../phet-core/js/EnumerationDeprecate
import moleculeShapes from '../../moleculeShapes.js';
import moleculeShapesStrings from '../../moleculeShapesStrings.js';

const shapeBentString = moleculeShapesStrings.shape.bent;
const shapeDiatomicString = moleculeShapesStrings.shape.diatomic;
const shapeEmptyString = moleculeShapesStrings.shape.empty;
const shapeLinearString = moleculeShapesStrings.shape.linear;
const shapeOctahedralString = moleculeShapesStrings.shape.octahedral;
const shapeSeesawString = moleculeShapesStrings.shape.seesaw;
const shapeSquarePlanarString = moleculeShapesStrings.shape.squarePlanar;
const shapeSquarePyramidalString = moleculeShapesStrings.shape.squarePyramidal;
const shapeTetrahedralString = moleculeShapesStrings.shape.tetrahedral;
const shapeTrigonalBipyramidalString = moleculeShapesStrings.shape.trigonalBipyramidal;
const shapeTrigonalPlanarString = moleculeShapesStrings.shape.trigonalPlanar;
const shapeTrigonalPyramidalString = moleculeShapesStrings.shape.trigonalPyramidal;
const shapeTShapedString = moleculeShapesStrings.shape.tShaped;

class MoleculeGeometryValue {
/*
* @param {number} x
* @param {string} string
* @param {IProperty<string>} stringProperty
*/
constructor( x, string ) {
constructor( x, stringProperty ) {
// @public {number}
this.x = x;

// @public {string}
this.string = string;
// @public {IProperty<string>}
this.stringProperty = stringProperty;
}
}

const MoleculeGeometry = EnumerationDeprecated.byMap( {
EMPTY: new MoleculeGeometryValue( 0, shapeEmptyString ),
DIATOMIC: new MoleculeGeometryValue( 1, shapeDiatomicString ),
LINEAR: new MoleculeGeometryValue( 2, shapeLinearString ), // e = 0,3,4
BENT: new MoleculeGeometryValue( 2, shapeBentString ), // e = 1,2
TRIGONAL_PLANAR: new MoleculeGeometryValue( 3, shapeTrigonalPlanarString ), // e = 0
TRIGONAL_PYRAMIDAL: new MoleculeGeometryValue( 3, shapeTrigonalPyramidalString ), // e = 1
T_SHAPED: new MoleculeGeometryValue( 3, shapeTShapedString ), // e = 2,3
TETRAHEDRAL: new MoleculeGeometryValue( 4, shapeTetrahedralString ), // e = 0
SEESAW: new MoleculeGeometryValue( 4, shapeSeesawString ), // e = 1
SQUARE_PLANAR: new MoleculeGeometryValue( 4, shapeSquarePlanarString ), // e = 2
TRIGONAL_BIPYRAMIDAL: new MoleculeGeometryValue( 5, shapeTrigonalBipyramidalString ), // e = 0
SQUARE_PYRAMIDAL: new MoleculeGeometryValue( 5, shapeSquarePyramidalString ), // e = 1
OCTAHEDRAL: new MoleculeGeometryValue( 6, shapeOctahedralString ) // e = 0
EMPTY: new MoleculeGeometryValue( 0, moleculeShapesStrings.shape.emptyProperty ),
DIATOMIC: new MoleculeGeometryValue( 1, moleculeShapesStrings.shape.diatomicProperty ),
LINEAR: new MoleculeGeometryValue( 2, moleculeShapesStrings.shape.linearProperty ), // e = 0,3,4
BENT: new MoleculeGeometryValue( 2, moleculeShapesStrings.shape.bentProperty ), // e = 1,2
TRIGONAL_PLANAR: new MoleculeGeometryValue( 3, moleculeShapesStrings.shape.trigonalPlanarProperty ), // e = 0
TRIGONAL_PYRAMIDAL: new MoleculeGeometryValue( 3, moleculeShapesStrings.shape.trigonalPyramidalProperty ), // e = 1
T_SHAPED: new MoleculeGeometryValue( 3, moleculeShapesStrings.shape.tShapedProperty ), // e = 2,3
TETRAHEDRAL: new MoleculeGeometryValue( 4, moleculeShapesStrings.shape.tetrahedralProperty ), // e = 0
SEESAW: new MoleculeGeometryValue( 4, moleculeShapesStrings.shape.seesawProperty ), // e = 1
SQUARE_PLANAR: new MoleculeGeometryValue( 4, moleculeShapesStrings.shape.squarePlanarProperty ), // e = 2
TRIGONAL_BIPYRAMIDAL: new MoleculeGeometryValue( 5, moleculeShapesStrings.shape.trigonalBipyramidalProperty ), // e = 0
SQUARE_PYRAMIDAL: new MoleculeGeometryValue( 5, moleculeShapesStrings.shape.squarePyramidalProperty ), // e = 1
OCTAHEDRAL: new MoleculeGeometryValue( 6, moleculeShapesStrings.shape.octahedralProperty ) // e = 0
}, {
beforeFreeze: MoleculeGeometry => {
/*
Expand Down
94 changes: 0 additions & 94 deletions js/common/model/VSEPRConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,11 @@

import Permutation from '../../../../dot/js/Permutation.js';
import moleculeShapes from '../../moleculeShapes.js';
import moleculeShapesStrings from '../../moleculeShapesStrings.js';
import AttractorModel from './AttractorModel.js';
import ElectronGeometry from './ElectronGeometry.js';
import LocalShape from './LocalShape.js';
import MoleculeGeometry from './MoleculeGeometry.js';

const shapeBentString = moleculeShapesStrings.shape.bent;
const shapeDiatomicString = moleculeShapesStrings.shape.diatomic;
const shapeEmptyString = moleculeShapesStrings.shape.empty;
const shapeLinearString = moleculeShapesStrings.shape.linear;
const shapeOctahedralString = moleculeShapesStrings.shape.octahedral;
const shapeSeesawString = moleculeShapesStrings.shape.seesaw;
const shapeSquarePlanarString = moleculeShapesStrings.shape.squarePlanar;
const shapeSquarePyramidalString = moleculeShapesStrings.shape.squarePyramidal;
const shapeTetrahedralString = moleculeShapesStrings.shape.tetrahedral;
const shapeTrigonalBipyramidalString = moleculeShapesStrings.shape.trigonalBipyramidal;
const shapeTrigonalPlanarString = moleculeShapesStrings.shape.trigonalPlanar;
const shapeTrigonalPyramidalString = moleculeShapesStrings.shape.trigonalPyramidal;
const shapeTShapedString = moleculeShapesStrings.shape.tShaped;

// for looking up VSEPRConfiguration instances
const configurationMap = {}; // x+','+e => {VSEPRConfiguration}

Expand Down Expand Up @@ -97,85 +82,6 @@ class VSEPRConfiguration {
Permutation.permutations( this.bondOrientations.length ) );
}

/**
* Returns the "geometry" name.
* @public
*
* @param {number} x - Number of radial atoms connected to the central atom
* @param {number} e - Number of radial lone pairs connected to the central atom
* @returns {string}
*/
static getName( x, e ) {
// figure out what the name is
if ( x === 0 ) {
return shapeEmptyString;
}
else if ( x === 1 ) {
return shapeDiatomicString;
}
else if ( x === 2 ) {
if ( e === 0 || e === 3 || e === 4 ) {
return shapeLinearString;
}
else if ( e === 1 || e === 2 ) {
return shapeBentString;
}
else {
throw new Error( `invalid x: ${x}, e: ${e}` );
}
}
else if ( x === 3 ) {
if ( e === 0 ) {
return shapeTrigonalPlanarString;
}
else if ( e === 1 ) {
return shapeTrigonalPyramidalString;
}
else if ( e === 2 || e === 3 ) {
return shapeTShapedString;
}
else {
throw new Error( `invalid x: ${x}, e: ${e}` );
}
}
else if ( x === 4 ) {
if ( e === 0 ) {
return shapeTetrahedralString;
}
else if ( e === 1 ) {
return shapeSeesawString;
}
else if ( e === 2 ) {
return shapeSquarePlanarString;
}
else {
throw new Error( `invalid x: ${x}, e: ${e}` );
}
}
else if ( x === 5 ) {
if ( e === 0 ) {
return shapeTrigonalBipyramidalString;
}
else if ( e === 1 ) {
return shapeSquarePyramidalString;
}
else {
throw new Error( `invalid x: ${x}, e: ${e}` );
}
}
else if ( x === 6 ) {
if ( e === 0 ) {
return shapeOctahedralString;
}
else {
throw new Error( `invalid x: ${x}, e: ${e}` );
}
}
else {
throw new Error( `unknown VSEPR configuration x: ${x}, e: ${e}` );
}
}

/*
* Returns cached VSEPRConfigurations based on radial atom/lone-pair counts.
* @public
Expand Down
Loading

1 comment on commit da82c96

@jonathanolson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.