Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                      <div class="container">
         <div class="row bottom-buffer">
            <div class="col-md-12 mb-4">
              <h3>Click to expand chart</h3>
            </div>  
           
           <div class="col-md-12">               
                  <div class="panel panel-default">
                     <div class="panel-heading" data-toggle="collapse" data-target="div#tddft" style="cursor: pointer; cursor: hand;">
                        <h4 class="panel-title">TDHF / TDDFT</h4>
                     </div>
                     <div id="tddft" class="panel-collapse collapse">
                        <div class="panel-body">
                           <div class="row bottom-buffer">
                              <div class="col-md-12">
                                 <div id="dipoleTransitionSpinFreePlotlyContainer" style="min-height:450px; width: 100%" class=" d-flex"></div>
                              </div>
                             
                              <div class="col-sm-12 col-md-12">
                                 <div id="dipoleTransitionSpinFreeContainerControls">
                                    <p style="text-align:right;padding:0px;font-weight: 400;"><input type="radio" name="tddftGraphUnits" value="ev" checked="true" onclick="tddftParametersChanged()">eV<input type="radio" name="tddftGraphUnits" value="cm1" onclick="tddftParametersChanged()">cm-1<input type="radio" name="tddftGraphUnits" value="nm" onclick="tddftParametersChanged()">nm</p>
                                    <p style="text-align:right;padding:0px;font-weight: 400;">Bandwidth: <input id="bandWidthSpinFree" type="text" size="5" value="0.15"></p>
                                    <p style="text-align:right;padding:0px;font-weight: 400;">min X: <input id="minXSpinFree" type="text" size="5" value="0"></p>
                                    <p style="text-align:right;padding:0px;font-weight: 400;">max X: <input id="maxXSpinFree" type="text" size="5" value="10"></p>
                                    <p style="text-align:right;padding:0px"><input type="button" value="Change" id="changeDipoleTransitionParametersButton" onclick="generateTddftChart()"></p>
                                    <p></p>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
            </div>               
       </div>        
    </div>

              
            
!

CSS

              
                .panel {
  -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
          box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.panel-default > .panel-heading {
  background-image: -webkit-linear-gradient(top, #f5f5f5 0%, #e8e8e8 100%);
  background-image: linear-gradient(to bottom, #f5f5f5 0%, #e8e8e8 100%);
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#ffe8e8e8', GradientType=0);
}

.panel-primary > .panel-heading {
  background-image: -webkit-linear-gradient(top, #428bca 0%, #357ebd 100%);
  background-image: linear-gradient(to bottom, #428bca 0%, #357ebd 100%);
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff428bca', endColorstr='#ff357ebd', GradientType=0);
}

.panel-success > .panel-heading {
  background-image: -webkit-linear-gradient(top, #dff0d8 0%, #d0e9c6 100%);
  background-image: linear-gradient(to bottom, #dff0d8 0%, #d0e9c6 100%);
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdff0d8', endColorstr='#ffd0e9c6', GradientType=0);
}

.panel-info > .panel-heading {
  background-image: -webkit-linear-gradient(top, #d9edf7 0%, #c4e3f3 100%);
  background-image: linear-gradient(to bottom, #d9edf7 0%, #c4e3f3 100%);
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9edf7', endColorstr='#ffc4e3f3', GradientType=0);
}

.panel-warning > .panel-heading {
  background-image: -webkit-linear-gradient(top, #fcf8e3 0%, #faf2cc 100%);
  background-image: linear-gradient(to bottom, #fcf8e3 0%, #faf2cc 100%);
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcf8e3', endColorstr='#fffaf2cc', GradientType=0);
}

.panel-danger > .panel-heading {
  background-image: -webkit-linear-gradient(top, #f2dede 0%, #ebcccc 100%);
  background-image: linear-gradient(to bottom, #f2dede 0%, #ebcccc 100%);
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2dede', endColorstr='#ffebcccc', GradientType=0);
}

.well {
  background-image: -webkit-linear-gradient(top, #e8e8e8 0%, #f5f5f5 100%);
  background-image: linear-gradient(to bottom, #e8e8e8 0%, #f5f5f5 100%);
  background-repeat: repeat-x;
  border-color: #dcdcdc;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffe8e8e8', endColorstr='#fff5f5f5', GradientType=0);
  -webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 0 rgba(255, 255, 255, 0.1);
          box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 0 rgba(255, 255, 255, 0.1);
}
              
            
!

JS

              
                //On expand accordion we'll generate our graph, to be correctly resized 
$('#tddft.panel-collapse').on('shown.bs.collapse', function () {
  tddftParametersChanged();                                   
})   


// The graph related function is generateTddftChart()

var evBandwidth = 0.15;
var cm1Bandwidth   = 1200;
var nmBandwidth = 20;

var evStep = evBandwidth / 30;
var cm1Step = cm1Bandwidth / 30;
var nmStep = nmBandwidth / 30;

var oscStrengths = [0,0.3884875293098869,0.3369143172519674E-01,0.3059851976517038E-08,0.8380452914768627,0.7088867394426135E-05,0.3870157583013627,0.5292183857790116E-01,0.1422450224365972,0.2090324099289508E-02,0.7611583447198612E-05,0.2236212525774453E-02,0.2038768507304741E-02]                          
var energyEv     = [0,5.191363250130026,5.321166466796516,6.401491005200247,7.003669078920944,7.057095961314860,7.125584759151358,7.147353609826066,7.340306540364482,7.763887845523734,8.004258184526714,8.249816534423726,8.592370934761625];                     
var energyCm1    = [0,41871.171828724684,42918.10546197172,51631.511208941425,56488.4053196778,56919.32222246488,57471.721676015535,57647.29931202313,59203.56977898143,62619.98368746959,64558.70137721524,66539.263200212,69302.15099406357];
var energyNm     = [0,238.828,233.002,193.680,177.027,175.687,173.999,173.469,168.909,159.693,154.898,150.287,144.296];

var energyMaxEv = round(8.6 + evBandwidth);                 
var energyMinEv = round(5.2 - evBandwidth);                
var energyMaxCm1 = round(69363.68356 + cm1Bandwidth);          
var energyMinCm1 = round(41940.831920000004 - cm1Bandwidth);
var energyMaxNm = round(238.43112884615383 + nmBandwidth);   
var energyMinNm = round(144.16765930232557 - nmBandwidth);     

function round(num){
  return Math.round(num * 100) / 100                                    
}

function tddftParametersChanged (){
  setTddftGraphLimitValues();        
  generateTddftChart();                       
}

function setTddftGraphLimitValues(){
  value = $("input[name='tddftGraphUnits']:checked").val();
  if(value == "ev"){                        		     
    $("#maxXSpinFree").val(energyMaxEv);
    $("#minXSpinFree").val(energyMinEv);      
    $("#bandWidthSpinFree").val(evBandwidth);            
  }
  if(value == "cm1"){     
    $("#maxXSpinFree").val(energyMaxCm1);
    $("#minXSpinFree").val(energyMinCm1);
    $("#bandWidthSpinFree").val(cm1Bandwidth);
  }
  if(value == "nm"){
    $("#maxXSpinFree").val(energyMaxNm);
    $("#minXSpinFree").val(energyMinNm);
    $("#bandWidthSpinFree").val(nmBandwidth);
  }
}

function generateTddftChart(){
  var data = fillTddftChart();

  var xLabel = "";                                        
  unitType = $("input[name='tddftGraphUnits']:checked").val();
  if(unitType == "ev")                        		              
    xLabel = '∆E (eV)';
  else if(unitType == "cm1")
    xLabel = '∆E (cm-1)';
  else  if(unitType == "nm")
    xLabel = "nm";

  var layout = {
    height: 450,
    xaxis: {
      title: xLabel,
      showgrid: true,
      zeroline: true,
      tickmode: 'auto'
    },
    hovermode: 'closest',
    yaxis: {
      title: 'Intensity [arb. units]'
    }
  };                                                
  Plotly.react('dipoleTransitionSpinFreePlotlyContainer', data, layout,  {responsive: true});
}

function fillTddftChart(){
  //Clear possible previous values                                        
  var data = new Array();
  var dataSum = new Array();

  // Now we'll generate root and all-roots-sum series and append them in data  and dataSum arrays
  var bandWidth = $("#bandWidthSpinFree").val();
  var minX = parseFloat($("#minXSpinFree").val());
  var maxX = parseFloat($("#maxXSpinFree").val());

  unitType = $("input[name='tddftGraphUnits']:checked").val();                                       
  for(var inx = 0; inx < oscStrengths.length; inx++){
    generateTddftValuesForRoot(data,dataSum,  inx+1, unitType,bandWidth, minX, maxX);
  }                                        

  var xVal = new Array();
  var yVal = new Array();
  var sum = 0;
  for(var inx = 0; inx < dataSum.length; inx++){
    xVal.push(dataSum[inx][0]);
    yVal.push(dataSum[inx][1]);
    sum += dataSum[inx][1];
  }

  //Check if there is representable data, if not (no osc.strength values) we'll not show graph 
  
  if(sum == 0){
    $('#dipoleTransitionSpinFreePlotlyContainer').hide();
    $('#dipoleTransitionSpinFreeContainerControls').hide();
    return;
  }

  //Add sum serie and plot graph
  var serie = {
    x: xVal,
    y: yVal,
    mode: 'lines',
    name: 'Total sum',
    marker: {         
      color: 'rgb(00, 00, 00)'
    }
  };                                                           
  data.push(serie);   
  return data;
}

function generateTddftValuesForRoot(data, dataSum, root, units, bandWidth, minX, maxX){
  var step;
  var energyValue;
  switch(units){
    case 'ev':  step = evStep;
      energyValue = energyEv[root-1];
      break;
    case 'cm1': step = cm1Step;
      energyValue = energyCm1[root-1];
      break;
    case 'nm':  step = nmStep;
      energyValue = energyNm[root-1];
      break;         
  }      

  var inx = 0;
  var xVal = new Array();
  var yVal = new Array();
  for(var x = minX; x < maxX ; x = x + step ) {  
    if(dataSum.length <= inx)     
      dataSum.push([x,oscStrengths[root-1] * Math.exp( -Math.pow(((2*Math.sqrt(2*Math.log(2)))/bandWidth),2) * Math.pow((x - energyValue),2))]);
    else
      dataSum[inx][1] += oscStrengths[root-1] * Math.exp( -Math.pow(((2*Math.sqrt(2*Math.log(2)))/bandWidth),2) * Math.pow((x - energyValue),2))

    xVal.push(x);
    yVal.push(oscStrengths[root-1] * Math.exp( -Math.pow(((2*Math.sqrt(2*Math.log(2)))/bandWidth),2) * Math.pow((x -energyValue),2)));
    inx++;
  }

  var serie = {
    x: xVal,
    y: yVal,
    mode: 'lines',
    name: 'Root ' + root,
  };                                                           
  data.push(serie);
}


function expandModule(moduleID){
  $('div#' + moduleID + ' div.panel-collapse:not(.show)').collapse('show');
}

function collapseModule(moduleID){
  $('div#' + moduleID + ' div.panel-collapse.show').collapse('hide');
}   
                      

                                    
                                    
              
            
!
999px

Console