/*******************************************************************************
*         McXtrace instrument definition URL=http://www.mcxtrace.org
*
* Instrument: Test_SAXS
*
* %Identification
* Written by: Martin Cramer Pedersen (mcpe@nbi.dk) and Søren Kynde (kynde@nbi.dk)
* Date: October 29th, 2012
* Origin: KU-Science
* %INSTRUMENT_SITE: Tests_samples
*
* Toy model used for testing various sample components for solution-SAXS.
*
* %Description
* Toy model used for testing various sample components for solution-SAXS.
*
* The following SAXS samples are handled:
* SAXSSpheres               SAMPLE=0
* SAXSShells                SAMPLE=1
* SAXSCylinders             SAMPLE=2
* SAXSEllipticCylinders     SAMPLE=3
* SAXSLiposomes             SAMPLE=4
* SAXSNanodiscs             SAMPLE=5
* SAXSNanodiscsWithTags     SAMPLE=6
* SAXSPDB                   SAMPLE=7 (very slow, rather use SAXSPDBFast)
* SAXSCurve                 SAMPLE=8 (inactivated)
* SAXSNanodiscsFast         SAMPLE=9
* SAXSNanodiscsWithTagsFast SAMPLE=10
* SAXSPDBFast               SAMPLE=11
*
* %Example: SAMPLE=0 Detector: PSDMonitor_I=2.93715e-14
* %Example: SAMPLE=1 Detector: PSDMonitor_I=2.7118e-14
* %Example: SAMPLE=2 Detector: PSDMonitor_I=2.64954e-14
* %Example: SAMPLE=3 Detector: PSDMonitor_I=9.77905e-15
* %Example: SAMPLE=4 Detector: PSDMonitor_I=1.16433e-10
* %Example: SAMPLE=5 Ncount=1e4 Detector: PSDMonitor_I=1.2001e-14
* %Example: SAMPLE=6 Ncount=1e4 Detector: PSDMonitor_I=1.05945e-14
* %Example: SAMPLE=7 Ncount=1e4 Detector: PSDMonitor_I=7.07865e-14
* %Example: SAMPLE=9 Detector: PSDMonitor_I=1.11073e-14
* %Example: SAMPLE=10 Detector: PSDMonitor_I=1.02884e-14
* %Example: SAMPLE=11 Detector: PSDMonitor_I=5.47707e-15
*
* %Parameters
* DistanceFromSourceToFirstPinhole: [m]  Distance to first pinhole from source.
* DistanceFromSourceToSecondPinhole: [m] Distance to second pinhole - used for focusing rays.
* DistanceFromSecondPinholeToSample: [m] Collimation length.
* DistanceFromSampleToDetector: [m]      Sample-detector-distance.
* RadiusOfDetector: [m]                  Radius of the circular detector.
* Lambda: [AA]                           Wavelength of the rays emitted from source.
* DLambda: [ ]                           Relative deviation of wavelength of the rays emitted from source.
* SAMPLE: [ ]                            Index of sample model, see above.
* Ncount:[1]                             Override the number of rays to simulate.
*
* %End
*******************************************************************************/

DEFINE INSTRUMENT Test_SAXS(
	DistanceFromSourceToFirstPinhole = 0.05,
	DistanceFromSourceToSecondPinhole = 0.7,
	DistanceFromSecondPinholeToSample = 0.6,
	DistanceFromSampleToDetector = 0.48,
	RadiusOfDetector = 0.1,
	Lambda = 1.54,
	DLambda = 0.01,
  SAMPLE=0, Ncount=0
)


INITIALIZE
%{
  if (Ncount>0)
    mcset_ncount(Ncount);
%}


TRACE
COMPONENT Origin = Progress_bar()
AT (0, 0, 0) ABSOLUTE


COMPONENT Source = Source_flat(
	xwidth = 0.0005,
	yheight = 0.0005,
	dist = DistanceFromSourceToSecondPinhole, 
	focus_yh = 0.0003, 
	focus_xw = 0.0003,
	lambda0 = Lambda, 
	dlambda = DLambda * Lambda
)
AT (0, 0, 0) RELATIVE Origin


COMPONENT FirstPinhole = Slit(
	radius = 0.0002
)
AT (0, 0, DistanceFromSourceToFirstPinhole) RELATIVE Source


COMPONENT SecondPinhole = Slit(
	radius = 0.00015
)
AT (0, 0, DistanceFromSourceToSecondPinhole) RELATIVE Source

COMPONENT Sample0 = SAXSSpheres(
	xwidth = 0.01,
	yheight = 0.01, 
	zdepth = 0.01,
	R = 50.0,
	SampleToDetectorDistance = DistanceFromSampleToDetector,
	DetectorRadius = RadiusOfDetector
)
WHEN(SAMPLE==0) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

COMPONENT Sample1 = SAXSShells(
	xwidth = 0.01,
	yheight = 0.01, 
	zdepth = 0.01,
	SampleToDetectorDistance = DistanceFromSampleToDetector,
	DetectorRadius = RadiusOfDetector,
	R = 50.0, 
	Thickness = 20.0
)
WHEN(SAMPLE==1) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

Component Sample2 = SAXSCylinders(
	xwidth = 0.01,
	yheight = 0.01,
	zdepth = 0.01,
	SampleToDetectorDistance = DistanceFromSampleToDetector,
	DetectorRadius = RadiusOfDetector
)
WHEN(SAMPLE==2) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

COMPONENT Sample3= SAXSEllipticCylinders(
	xwidth = 0.01,
	yheight = 0.01,
	zdepth = 0.01,
	SampleToDetectorDistance = DistanceFromSampleToDetector,
	DetectorRadius = RadiusOfDetector
)
WHEN(SAMPLE==3) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

COMPONENT Sample4= SAXSLiposomes(
	xwidth = 0.01,
	yheight = 0.01,
	zdepth = 0.01,
	SampleToDetectorDistance = DistanceFromSampleToDetector,
	DetectorRadius = RadiusOfDetector
)
WHEN(SAMPLE==4) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

COMPONENT Sample5= SAXSNanodiscs(
	xwidth = 0.01,
	yheight = 0.01,
	zdepth = 0.01,
	SampleToDetectorDistance = DistanceFromSampleToDetector,
	DetectorRadius = RadiusOfDetector
)
WHEN(SAMPLE==5) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

COMPONENT Sample6= SAXSNanodiscsWithTags(
	xwidth = 0.01,
	yheight = 0.01,
	zdepth = 0.01,
	SampleToDetectorDistance = DistanceFromSampleToDetector,
	DetectorRadius = RadiusOfDetector
)
WHEN(SAMPLE==6) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

COMPONENT Sample7 = SAXSPDB(
	xwidth = 0.01,
 	yheight = 0.01,
 	zdepth = 0.01,
 	SampleToDetectorDistance = DistanceFromSampleToDetector,
 	DetectorRadius = RadiusOfDetector,
 	PDBFilepath = "3v03.pdb"
 )
WHEN(SAMPLE==7) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

//COMPONENT Sample8 = SAXSCurve(
//	FileWithCurve = "Curve.mcp",
//	xwidth = 0.01,
//	yheight = 0.01,
//	zdepth = 0.01,
//	SampleToDetectorDistance = DistanceFromSampleToDetector,
//	DetectorRadius = RadiusOfDetector
//)
//WHEN(SAMPLE==8) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

COMPONENT Sample9 = SAXSNanodiscsFast(
	xwidth = 0.01,
	yheight = 0.01,
	zdepth = 0.01,
	SampleToDetectorDistance = DistanceFromSampleToDetector,
	DetectorRadius = RadiusOfDetector
)
WHEN(SAMPLE==9) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

COMPONENT Sample10 = SAXSNanodiscsWithTagsFast(
	xwidth = 0.01,
	yheight = 0.01,
	zdepth = 0.01,
	SampleToDetectorDistance = DistanceFromSampleToDetector,
	DetectorRadius = RadiusOfDetector
)
WHEN(SAMPLE==10) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

COMPONENT Sample11 = SAXSPDBFast(
 	xwidth = 0.01,
 	yheight = 0.01,
 	zdepth = 0.01,
 	SampleToDetectorDistance = DistanceFromSampleToDetector,
 	DetectorRadius = RadiusOfDetector, 
 	PDBFilepath = "6lyz.pdb", NumberOfQBins=2000,
     qMax = 0.9
 )
WHEN(SAMPLE==11) AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole

COMPONENT Beamstop = Beamstop(
	radius = 0.001
)
AT (0, 0, DistanceFromSampleToDetector - 0.000001) RELATIVE Sample0


COMPONENT PSDMonitor = PSD_monitor(
	filename = "PSDMonitor",
	xwidth = 2.0 * RadiusOfDetector / sqrt(2.0), 
	yheight = 2.0 * RadiusOfDetector / sqrt(2.0),
	nx = 200,
	ny = 200,
	restore_xray = 1
)
AT (0, 0, 0.000001) RELATIVE Beamstop


COMPONENT QMonitor = SAXSQMonitor(
	RadiusDetector = RadiusOfDetector,
	DistanceFromSample = DistanceFromSampleToDetector,
	LambdaMin = Lambda,
	Lambda0 = Lambda,
	NumberOfBins = 2000
)
AT (0, 0, 0.000001000000001) RELATIVE Beamstop


END
