Beispiel #1
0
    getPossibleMoleculeStructureFromBond: function( a, b ) {
      var molA = this.getMolecule( a );
      var molB = this.getMolecule( b );
      assert && assert( molA !== molB );

      return MoleculeStructure.getCombinedMoleculeFromBond( molA, molB, a, b, new Molecule() );
    },
Beispiel #2
0
    bond: function( a, dirAtoB, b ) {
      this.lewisDotModel.bond( a, dirAtoB, b );
      var molA = this.getMolecule( a );
      var molB = this.getMolecule( b );
      if ( molA === molB ) {
        throw new Error( 'WARNING: loop or other invalid structure detected in a molecule' );
      }

      var newMolecule = MoleculeStructure.getCombinedMoleculeFromBond( molA, molB, a, b, new Molecule() );

      // sanity check and debugging information
      if ( !newMolecule.isValid() ) {
        // TODO: performance: strip this out for the runtime?
        window.console && console.log && console.log( 'invalid molecule!' );
        window.console && console.log && console.log( 'bonding: ' + a.symbol + '(' + a.reference + '), ' + dirAtoB + ' ' + b.symbol + ' (' + b.reference + ')' );
        window.console && console.log && console.log( 'A' );
        window.console && console.log && console.log( molA.getDebuggingDump() );
        window.console && console.log && console.log( 'B' );
        window.console && console.log && console.log( molB.getDebuggingDump() );
        window.console && console.log && console.log( 'combined' );
        window.console && console.log && console.log( newMolecule.getDebuggingDump() );

        window.console && console.log && console.log( 'found: ' + this.isAllowedStructure( newMolecule ) );

        // just exit out for now
        return;
      }

      this.removeMolecule( molA );
      this.removeMolecule( molB );
      this.addMolecule( newMolecule );

      /*---------------------------------------------------------------------------*
       * bonding diagnostics and sanity checks
       *----------------------------------------------------------------------------*/

      var serializedForm = this.getMolecule( a ).toSerial2();
      window.console && console.log && console.log( 'created structure: ' + serializedForm );
      var structure = this.getMolecule( a );
      if ( structure.atoms.length > 2 ) {
        structure.bonds.forEach( function( bond ) {
          if ( bond.a.hasSameElement( bond.b ) && bond.a.symbol === 'H' ) {
            window.console && console.log && console.log( 'WARNING: Hydrogen bonded to another hydrogen in a molecule which is not diatomic hydrogen' );
          }
        } );
      }

      assert && assert( this.getMolecule( a ) === this.getMolecule( b ) );
    },