-------------------------------------------------------------------------------
--                                                                           --
--                          Experiment Source Code                           --
--              Delta NMR Experiment & Machine Control Interface             --
--                                                                           --
--                     Copyright (c) 2015 JEOL Ltd                           --
--                            All Rights Reserved                            --
--                                                                           --
-------------------------------------------------------------------------------
-- HELP.eng: double_cp_2d
-- Category: solids, ultrafast mas, 2D, heteronuclear correlation and homonuclear correlation.
-- By Rongchun Zhang, 2021/12/14
header
    filename    => "TQ_DQ_SQ_double_cp_2d";
    sample_id   => "";
    comment     => "double_cp_2d";
    process     = "2d_solid.list";
    include "header_solid";
end header;

instrument
    include "instrument_solid";
end instrument;

acquisition
    x_domain    =>  "Proton";
    x_offset    =>  5[ppm];
    x_sweep     =>  100[kHz];
    x_points    =>  1024;
    scans       =>  8;
    x_prescans  =>  0;
    mod_return  =>  2;

    z_domain    =>  "Carbon13";
    z_offset    =>  100[ppm];
    z_sweep     =>  20[kHz], help "rotor-synchronization";
	z_dwell     =?  1/z_sweep;
    z_points    =>  32;
    z_acq_time      =?  z_points / z_sweep;
	
    y_domain         =?  x_domain;
    y_offset         =  x_offset * 3;
    y_sweep          => 30[kHz], help "rotor-synchronization";
    y_dwell          =? 1/y_sweep;
    y_points         => 16;
	y_acq_time      =?  y_points / y_sweep;
	
    include "acquisition_solid";
    include "acquisition_2d";

end acquisition;

pulse
    collect COMPLEX,OBS COMPLEX Complex,IRR;
    initial_wait    =   10.0[ms];

    	irr_domain       => "Carbon13" , help "decoupled nucleus";
	irr_offset       => 100[ppm] , help "decoupler offset";

Pulse_Setup =? "#Setup hard pulses#";

    obs_width_90    => x90;
    obs_width_180   => x90*2;
	obs_width_2q		=>	x90;
    obs_amp_pulse   => 100[%], 0[%]->100[%] : 10[m%];
    irr_width_90    => irr90;
    irr_width_180   => irr90*2;
    irr_amp_pulse   => 100[%];

CP1_Setup   =? "#Setup first CP#";

    obs_shape_cp     = "RAMP_cp";
    contact_time     => 2[ms], 0[us]->20[ms] : 10[us], help "contact time";
    obs_amp_cp       => 30[%], 0[%]->100[%] : 10[m%], help "CP amplitude of irr channel";
    obs_amp_grad     => 10[%], -100[%]->100[%] : 0.1[%], help "irr CP sweep range (-irr_amp_grad/2->+irr_amp_grad)";

    irr_shape_cp     = "RAMP_cp";
    irr_amp_cp       => 30[%], 0[%]->100[%] : 10[m%], help "amplitude of obs channel";
    irr_amp_grad     => 1[%], -100[%]->100[%] : 0.1[%], help "obs CP sweep range (-obs_amp_grad/2->+obs_amp_grad)";

CP2_Setup   =? "#Setup second CP#";

    obs_shape_cp2    = "RAMP_cp2";
    contact_time2    => 0.5[ms], 0[us]->20[ms] : 10[us], help "contact time";
    obs_amp_cp2      => obs_amp_cp, 0[%]->100[%] : 10[m%], help "CP amplitude of irr channel";
    obs_amp_grad2    => -obs_amp_grad;

    irr_shape_cp2    =  "RAMP_cp2";
    irr_amp_cp2      => irr_amp_cp, 0[%]->100[%] : 10[m%], help "amplitude of obs channel";
    irr_amp_grad2    => -irr_amp_grad;


OBSdec_Setup =? "#Setup OBS dec#";

    obs_noise       => "CW", ("CM", "CW", "SPINAL64", "SPINAL64_vp", "swfTPPM", "TPPM", "XiX"), help "decoupling sequence";
    obs_amp_dec     => 5[%], 0[%]->100[%] : 10[m%], help "amplitude of decoupling";
    when obs_noise /= "CW" and obs_noise /= "XIX" do
        obs_width_nominal90 => x90 * 100[%] / obs_amp_dec, help "modulation pulse width for decoupling";
    end when;
    when obs_noise = "CM" or obs_noise = "SPINAL64_vp" or obs_noise = "swfTPPM" or obs_noise = "TPPM" do
        obs_phs_tppm        => 15[deg], help "decoupling sequence phase modulation";
    end when;
    when obs_noise = "XiX" do
        obs_width_xix       => 50[us], help "XiX modulation pulse width: should be optimized around 1.85*tr";
    end when;
    obs_pwidth          =  if obs_noise = "CW"
                           then 0[us]
                           else if obs_noise = "XiX"
                           then obs_width_xix
                           else obs_width_nominal90;

RN_Setup	=? "-----------Setup RN pulses-----------";
	spinning_freq		=> 60 [kHz];
	number_large_N		=>	30;
	number_n		=>	6;
	number_nu		=>	10;
	number_RN		=>	1;
	obs_amp_RN		=>	60[%];
	obs_phs_RN_p		=	180*number_nu/number_large_N;
	obs_phs_RN_m		=	-obs_phs_RN_p;
	obs_width_RN		=	(number_n/spinning_freq)/number_large_N;
	supercycle			=>	"S0Sinv", ("S0","S0Sinv");
	recoupling			=?	if supercycle = "S0" then number_RN*number_n/spinning_freq
					else	if supercycle = "S0Sinv" then 2*number_RN*number_n/spinning_freq
					else 0[us];

	z_filter1		=>	100[us];
	z_filter2		=>	100[us];				   

HORROR_Setup =? "#Setup HORROR#";

    tau_rr      => 1[ms], 0[us]->100[ms] : 10[us];
    obs_amp_rr  => 10[%];

MISC_Setup  =? "#Setup Miscellaneous#";


-------------------------------------------------------------------------------------
--found: COG 16 (15,1,0; 8)
--selected pathways: 2
--#0:
--nuc 1: 0 -3 2 0 
--#1:
--nuc 1: 0 3 -2 0 
--------------------------------------------
      obs_phs_exc	=	{  0..15*15*360/16:15*360/16,  30..(30+15*15*360/16):15*360/16,
					   0..15*15*360/16:15*360/16,  30..(30+15*15*360/16):15*360/16}.ystep(60%2);

	obs_phs_exc2q	=	{  0..15*1*360/16:1*360/16,  0..15*1*360/16:1*360/16,
				       18..(18+15*1*360/16):1*360/16,  18..(18+15*1*360/16):1*360/16}.zstep(36%2);	

  
	obs_phs_rec2q	=	{ 0};
	obs_phs_rec	=	{ 0};
     obs_phs_read        =   {16(0),16(120),16(240)};
	obs_phs_acq1		=	{8( 0,180),8(120,300),8(240, 60)}.ystep(180%2).zstep(180%2);


    relaxation_delay    =>  5[s],                           help "inter-pulse delay";
    repetition_time     =?  relaxation_delay + x_acq_time + y_acq_time,  help "relaxation_delay+x_acq_time";

    obs_atn             =>  xatn,   help "attenuator of obs";
    irr_atn             =>  irratn, help "attenuator of irr";

    obs_phs_prep        =   {0};
    obs_phs_cp1         =   { 90};
    obs_phs_dec         =   {90};
    obs_phs_cp2         =   {2(90),2(270)};
    obs_phs_store       =   {180};
    
    obs_phs_rrx         =    {0};
    obs_phs_rry         = {90};

    irr_phs_cp1         =   {90};
    irr_phs_store       =   {180};
    irr_phs_restore     =   {{0,180},{0,180},{90,270},{90,270}}.zstep(180%2);
    irr_phs_cp2         =   {90};
    irr_phs_dec         =   {0};
    irr_phs_befHORROR   =   {180};
    irr_phs_aftHORROR   =   {0};

     obs_phs_acq2        =  {  90,270,270, 90}.ystep(0%2).zstep(180%2);

    include "pulse_solid";

    module_config = "solid_sample continuous_fid";

begin
    initial_wait;


    relaxation_delay;

    obs_width_90,   (obs.gate,  obs.phs.obs_phs_prep,   obs.amp.obs_amp_pulse,  obs.atn.obs_atn);

    contact_time, (obs.GATE, obs.PHS.obs_phs_cp1, obs.shape.{obs_shape_cp, "obs"}, obs.ATN.obs_atn,
                   irr.GATE, irr.PHS.irr_phs_cp1, irr.SHAPE.{irr_shape_cp, "irr"}, irr.ATN.irr_atn);

    align center
    irr_width_90, (irr.gate, irr.phs.irr_phs_store, irr.amp.irr_amp_pulse, irr.atn.irr_atn);
    obs_width_90, (obs.gate, obs.phs.obs_phs_store, obs.amp.obs_amp_pulse, obs.atn.obs_atn);
    end align;  
 
    z_filter1;

loop number_RN times
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_exc),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_exc),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
when supercycle = "S0Sinv" do
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_exc),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_exc),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
end when;
end loop;

loop number_RN times
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_exc+120),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_exc+120),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
when supercycle = "S0Sinv" do
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_exc-120),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_exc-120),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
end when;
end loop;

loop number_RN times
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_exc+240),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_exc+240),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
when supercycle = "S0Sinv" do
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_exc-240),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_exc-240),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
end when;
end loop;


   0[us] ystep 1/y_sweep;

   obs_width_2q,	(obs.gate, obs.phs.obs_phs_exc2q, obs.amp.obs_amp_pulse, obs.atn.obs_atn);

	0[us] zstep 1/z_sweep;

	obs_width_2q,	(obs.gate, obs.phs.obs_phs_rec2q, obs.amp.obs_amp_pulse, obs.atn.obs_atn);
	
	loop number_RN times
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_rec),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_rec),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
when supercycle = "S0Sinv" do
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_rec),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_rec),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
end when;
end loop;

loop number_RN times
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_rec+120),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_rec+120),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
when supercycle = "S0Sinv" do
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_rec-120),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_rec-120),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
end when;
end loop;

loop number_RN times
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_rec+240),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_rec+240),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
when supercycle = "S0Sinv" do
loop number_large_N/2 times
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_m+obs_phs_rec-240),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
	obs_width_RN,	(obs.gate,	obs.phs.(obs_phs_RN_p+obs_phs_rec-240),	obs.amp.obs_amp_RN,	obs.atn.obs_atn);
end loop;
end when;
end loop;

  z_filter2;
   obs_width_90,   (obs.gate,  obs.phs.obs_phs_read,   obs.amp.obs_amp_pulse,  obs.atn.obs_atn);

    acq(dead_time, delay, obs_phs_acq1 );

    irr_width_90,   (irr.gate,  irr.phs.irr_phs_restore,    irr.amp.irr_amp_pulse,  irr.atn.irr_atn);

   0[us] zstep 1/z_sweep, (obs.GATE, obs.PHS.obs_phs_dec, obs.AMP.obs_amp_dec, obs.ATN.obs_atn, obs.noise.obs_noise);

    irr_width_90,   (irr.gate,  irr.phs.irr_phs_befHORROR,    irr.amp.irr_amp_pulse,  irr.atn.irr_atn);

    tau_rr, (OBS.GATE, OBS.PHS.obs_phs_rrx, OBS.AMP.obs_amp_rr, OBS.ATN.obs_atn);
    tau_rr, (OBS.GATE, OBS.PHS.obs_phs_rry, OBS.AMP.obs_amp_rr, OBS.ATN.obs_atn);
    tau_rr, (OBS.GATE, OBS.PHS.obs_phs_rrx, OBS.AMP.obs_amp_rr, OBS.ATN.obs_atn);
    tau_rr, (OBS.GATE, OBS.PHS.obs_phs_rry, OBS.AMP.obs_amp_rr, OBS.ATN.obs_atn);

    irr_width_90,   (irr.gate,  irr.phs.irr_phs_aftHORROR,    irr.amp.irr_amp_pulse,  irr.atn.irr_atn);


    contact_time2, (obs.GATE, obs.PHS.obs_phs_cp2, obs.shape.{obs_shape_cp2, "obs"}, obs.ATN.obs_atn,
                    irr.GATE, irr.PHS.irr_phs_cp2, irr.SHAPE.{irr_shape_cp2, "irr"}, irr.ATN.irr_atn);
    
    
    acq( dead_time, delay, obs_phs_acq2 );
   
end pulse;